Save post content

This commit is contained in:
Sam Ireland 2020-12-30 23:47:15 +00:00
parent 6a171ad2d5
commit 92d25dc356
2 changed files with 10 additions and 0 deletions

View File

@ -1,4 +1,10 @@
<div class="post"> <div class="post">
<h2><!--title--></h2> <h2><!--title--></h2>
<time title="<!--timestamp-->"><!--date--></time> <time title="<!--timestamp-->"><!--date--></time>
<a href="<!--link-->">Link</a>
<div class="subreddit"><!--subreddit--></div>
<div class="user"><!--user--></div>
<div class="body">
<!--body-->
</div>
</div> </div>

View File

@ -31,6 +31,10 @@ def get_post_html(post):
html = f.read() html = f.read()
dt = datetime.utcfromtimestamp(post.created_utc) dt = datetime.utcfromtimestamp(post.created_utc)
html = html.replace("<!--title-->", post.title) html = html.replace("<!--title-->", post.title)
html = html.replace("<!--subreddit-->", f"/r/{str(post.subreddit)}")
html = html.replace("<!--user-->", f"/u/{post.author.name}" if post.author else "[deleted]")
html = html.replace("<!--link-->", f"https://reddit.com{post.permalink}")
html = html.replace("<!--body-->", post.selftext_html or "")
html = html.replace("<!--timestamp-->", str(dt)) html = html.replace("<!--timestamp-->", str(dt))
html = html.replace("<!--date-->", dt.strftime("%d %B, %Y")) html = html.replace("<!--date-->", dt.strftime("%d %B, %Y"))
return html return html