diff --git a/html/comment-div.html b/html/comment-div.html new file mode 100644 index 0000000..b1647e1 --- /dev/null +++ b/html/comment-div.html @@ -0,0 +1,6 @@ +
+
+
+ +
+
\ No newline at end of file diff --git a/html/post.html b/html/post.html index 6b9a7bf..b6f9851 100644 --- a/html/post.html +++ b/html/post.html @@ -8,6 +8,7 @@

Comments

+
\ No newline at end of file diff --git a/utilities.py b/utilities.py index 939c41c..ba4d057 100644 --- a/utilities.py +++ b/utilities.py @@ -28,7 +28,7 @@ def get_saved_posts(client): """Gets a list of posts that the user has saved.""" return [ - saved for saved in client.user.me().saved(limit=None) + saved for saved in client.user.me().saved(limit=20) if saved.__class__.__name__ == "Submission" ] @@ -167,4 +167,22 @@ def create_post_page_html(post, post_html): )) with open(os.path.join("html", "style.css")) as f: html = html.replace("", f"") + comments_html = [] + post.comments.replace_more(limit=0) + for comment in post.comments: + comments_html.append(get_comment_html(comment)) + html = html.replace("", "\n".join(comments_html)) + return html + + +def get_comment_html(comment): + with open(os.path.join("html", "comment-div.html")) as f: + html = f.read() + dt = datetime.utcfromtimestamp(comment.created_utc) + html = html.replace("", f"/u/{comment.author.name}" if comment.author else "[deleted]") + html = html.replace("", comment.body_html or "") + html = html.replace("", str(comment.score)) + html = html.replace("", f"https://reddit.com{comment.permalink}") + html = html.replace("", str(dt)) + html = html.replace("", dt.strftime("%H:%M - %d %B, %Y")) return html \ No newline at end of file