diff --git a/html/post-div.html b/html/post-div.html new file mode 100644 index 0000000..88a2040 --- /dev/null +++ b/html/post-div.html @@ -0,0 +1,16 @@ +
+

+ +Link +reddit Link +Content Link +
+
+
+ +
+
+ +
+ +
\ No newline at end of file diff --git a/html/post.html b/html/post.html index 1184ed0..6b9a7bf 100644 --- a/html/post.html +++ b/html/post.html @@ -1,15 +1,13 @@ -
-

- -Link -Content Link -
-
-
- -
-
- -
+ + +<!--title--> + + -
\ No newline at end of file + + +
+

Comments

+
+ + \ No newline at end of file diff --git a/save.py b/save.py index 16cc8c1..8dd900b 100755 --- a/save.py +++ b/save.py @@ -29,9 +29,11 @@ else: html_file = "upvoted.html" get_posts = get_upvoted_posts -# Make directory for media +# Make directory for media and posts if not os.path.exists(os.path.join(location, "media")): os.mkdir(os.path.join(location, "media")) +if not os.path.exists(os.path.join(location, "posts")): + os.mkdir(os.path.join(location, "posts")) # Are there any posts already? post_ids, posts_html = [], [] @@ -55,6 +57,9 @@ else: if media: post_html = add_media_preview_to_html(post_html, media) posts_html.append(post_html) + page_html = create_post_page_html(post, post_html) + with open(os.path.join(location, "posts", f"{post.id}.html"), "w") as f: + f.write(page_html) # Save HTML with open(os.path.join("html", html_file)) as f: @@ -65,3 +70,4 @@ 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 22952b8..939c41c 100644 --- a/utilities.py +++ b/utilities.py @@ -46,13 +46,14 @@ def get_post_html(post): """Takes a post object and creates a HTML for it - but not including the preview HTML.""" - with open(os.path.join("html", "post.html")) as f: + with open(os.path.join("html", "post-div.html")) as f: html = f.read() dt = datetime.utcfromtimestamp(post.created_utc) html = html.replace("", post.title) html = html.replace("", f"/r/{str(post.subreddit)}") 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("", f"posts/{post.id}.html") + 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 "") @@ -154,4 +155,16 @@ def add_media_preview_to_html(post_html, media): "", f'' ) - return post_html \ No newline at end of file + return post_html + + +def create_post_page_html(post, post_html): + with open(os.path.join("html", "post.html")) as f: + html = f.read() + html = html.replace("", post.title) + html = html.replace("", post_html.replace("h2>", "h1>").replace( + '", f"") + return html \ No newline at end of file