import os import praw import requests from redvid import Downloader import yt_dlp import re from datetime import datetime try: from logindata import REDDIT_USERNAME, REDDIT_PASSWORD from logindata import REDDIT_CLIENT_ID, REDDIT_SECRET except ImportError: REDDIT_USERNAME = os.getenv("REDDIT_USERNAME") REDDIT_PASSWORD = os.getenv("REDDIT_PASSWORD") REDDIT_CLIENT_ID = os.getenv("REDDIT_CLIENT_ID") REDDIT_SECRET = os.getenv("REDDIT_SECRET") IMAGE_EXTENSIONS = ["gif", "gifv", "jpg", "jpeg", "png"] VIDEO_EXTENSIONS = ["mp4"] PLATFORMS = ["redgifs.com", "gfycat.com", "imgur.com", "youtube.com"] def make_client(): """Creates a PRAW client with the details in the secrets.py file.""" print(REDDIT_USERNAME) return praw.Reddit( username=REDDIT_USERNAME, password=REDDIT_PASSWORD, client_id=REDDIT_CLIENT_ID, client_secret=REDDIT_SECRET, user_agent="reddit-save", ) def get_previous(location, html_file): html_files = [f for f in os.listdir(location) if f.endswith(".html")] pattern = html_file.replace(".html", r"\.(\d+)?\.html") matches = [re.match(pattern, f) for f in html_files] matches = [m[0] for m in matches if m] matches.sort(key=lambda x: int(x.split(".")[1])) existing_ids = [] existing_posts_html = [] existing_comments_html = [] if html_file in html_files: matches.append(html_file) for match in matches: with open(os.path.join(location, match), encoding="utf-8") as f: current_html = f.read() for id in re.findall(r'id="(.+?)"', current_html): if id not in existing_ids: existing_ids.append(id) posts = re.findall( r'(