diff --git a/html/post.html b/html/post.html index c2fa751..1184ed0 100644 --- a/html/post.html +++ b/html/post.html @@ -1,4 +1,4 @@ -
+

Link @@ -11,4 +11,5 @@
-
\ No newline at end of file + +
\ No newline at end of file diff --git a/save.py b/save.py index 3b26635..16cc8c1 100755 --- a/save.py +++ b/save.py @@ -2,6 +2,7 @@ import argparse import os +import re from tqdm import tqdm from utilities import * @@ -32,24 +33,35 @@ else: if not os.path.exists(os.path.join(location, "media")): os.mkdir(os.path.join(location, "media")) -posts_html = [] +# Are there any posts already? +post_ids, posts_html = [], [] +if os.path.exists(os.path.join(location, html_file)): + with open(os.path.join(location, html_file)) as f: + current_html = f.read() + post_ids = re.findall(r'id="(.+?)"', current_html) + posts_html = re.findall( + r'(
<\/div>)', + current_html + ) -posts = get_posts(client) -for post in tqdm(posts): - post_html = get_post_html(post) - media = save_media(post, location) - if media: - post_html = add_media_preview_to_html(post_html, media) - posts_html.append(post_html) +# Get posts HTML +posts = [p for p in get_posts(client) if p.id not in post_ids] +if not posts: + print("No new saved posts") +else: + for post in tqdm(posts): + post_html = get_post_html(post) + media = save_media(post, location) + if media: + post_html = add_media_preview_to_html(post_html, media) + posts_html.append(post_html) +# Save HTML with open(os.path.join("html", html_file)) as f: html = f.read() - with open(os.path.join("html", "style.css")) as f: html = html.replace("", f"") - html = html.replace("", "\n".join(posts_html)) - with open(os.path.join(location, html_file), "w") as f: f.write(html) diff --git a/utilities.py b/utilities.py index cebe547..22952b8 100644 --- a/utilities.py +++ b/utilities.py @@ -8,7 +8,7 @@ from datetime import datetime from secrets import REDDIT_USERNAME, REDDIT_PASSWORD from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET -IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "gifv"] +IMAGE_EXTENSIONS = ["gif", "gifv", "jpg", "jpeg", "png"] VIDEO_EXTENSIONS = ["mp4"] PLATFORMS = ["redgifs.com", "gfycat.com", "imgur.com", "youtube.com"] @@ -38,7 +38,7 @@ def get_upvoted_posts(client): return [ upvoted for upvoted in client.user.me().upvoted(limit=None) - if saved.__class__.__name__ == "Submission" + if upvoted.__class__.__name__ == "Submission" ] @@ -54,6 +54,7 @@ def get_post_html(post): html = html.replace("", f"/u/{post.author.name}" if post.author else "[deleted]") html = html.replace("", f"https://reddit.com{post.permalink}") html = html.replace("", post.url) + html = html.replace("", post.id) html = html.replace("", post.selftext_html or "") html = html.replace("", str(dt)) html = html.replace("", dt.strftime("%d %B, %Y"))