Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion imgur_scraper/imgur_scraper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import csv
import datetime
from datetime import date, timedelta
import json
import os

Expand All @@ -26,6 +27,7 @@ def get_viral_posts_from(start_date: str, end_date: str) -> json:
"Grabbing "
+ " ".join(r.html.find(".images-header-main")[0].full_text.split())
)
date_img = date.today() - timedelta(days=days_ago)
while not r.html.find("#nomore"):
for entries in r.html.find(".post"):
yield {
Expand All @@ -37,6 +39,7 @@ def get_viral_posts_from(start_date: str, end_date: str) -> json:
.rstrip(),
"type": entries.find(".post-info")[0].full_text.strip().split()[0],
"views": entries.find(".post-info")[0].full_text.strip().split()[2],
"date": date_img.strftime('%Y-%m-%d')
}
counter += 1
r = HTMLSession().get(
Expand Down Expand Up @@ -96,7 +99,7 @@ def main():
try:
file_name = os.path.join(path, f"{start_date}_to_{end_date}_imgur_data.csv")
with open(file_name, "x", newline="", encoding="utf-8") as csvfile:
fieldnames = ["title", "url", "points", "tags", "type", "views"]
fieldnames = ["title", "url", "points", "tags", "type", "views", "date"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(get_viral_posts_from(start_date, end_date))
Expand Down