Save top-level comments
This commit is contained in:
parent
01cc17e408
commit
301e95b450
6
html/comment-div.html
Normal file
6
html/comment-div.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div class="comment">
|
||||||
|
<div class="user"><!--user--></div>
|
||||||
|
<div class="score"><!--score--></div>
|
||||||
|
<a href="<!--link-->"><time title="<!--timestamp-->"><!--date--></time></a>
|
||||||
|
<div class="body"><!--body--></div>
|
||||||
|
</div>
|
@ -8,6 +8,7 @@
|
|||||||
<!--post-->
|
<!--post-->
|
||||||
<div class="comments">
|
<div class="comments">
|
||||||
<h2>Comments</h2>
|
<h2>Comments</h2>
|
||||||
|
<!--comments-->
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
20
utilities.py
20
utilities.py
@ -28,7 +28,7 @@ def get_saved_posts(client):
|
|||||||
"""Gets a list of posts that the user has saved."""
|
"""Gets a list of posts that the user has saved."""
|
||||||
|
|
||||||
return [
|
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"
|
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:
|
with open(os.path.join("html", "style.css")) as f:
|
||||||
html = html.replace("<style></style>", f"<style>\n{f.read()}\n</style>")
|
html = html.replace("<style></style>", f"<style>\n{f.read()}\n</style>")
|
||||||
|
comments_html = []
|
||||||
|
post.comments.replace_more(limit=0)
|
||||||
|
for comment in post.comments:
|
||||||
|
comments_html.append(get_comment_html(comment))
|
||||||
|
html = html.replace("<!--comments-->", "\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("<!--user-->", f"/u/{comment.author.name}" if comment.author else "[deleted]")
|
||||||
|
html = html.replace("<!--body-->", comment.body_html or "")
|
||||||
|
html = html.replace("<!--score-->", str(comment.score))
|
||||||
|
html = html.replace("<!--link-->", f"https://reddit.com{comment.permalink}")
|
||||||
|
html = html.replace("<!--timestamp-->", str(dt))
|
||||||
|
html = html.replace("<!--date-->", dt.strftime("%H:%M - %d %B, %Y"))
|
||||||
return html
|
return html
|
Loading…
Reference in New Issue
Block a user