Get upvoted posts

This commit is contained in:
Sam Ireland 2020-12-30 23:05:45 +00:00
parent 93225db543
commit 6a171ad2d5
3 changed files with 26 additions and 3 deletions

10
html/upvoted.html Normal file
View File

@ -0,0 +1,10 @@
<html>
<head>
<title>Upvoted Posts</title>
</head>
<body>
<h1>Upvoted Posts</h1>
<!--posts-->
</body>
</html>

13
save.py
View File

@ -19,17 +19,24 @@ if not os.path.isdir(location):
# Make a client object
client = make_client()
if mode == "saved":
html_file = "saved.html"
get_posts = get_saved_posts
else:
html_file = "upvoted.html"
get_posts = get_upvoted_posts
posts_html = []
for post in get_saved_posts(client):
for post in get_posts(client):
posts_html.append(get_post_html(post))
with open(os.path.join("html", "saved.html")) as f:
with open(os.path.join("html", html_file)) as f:
html = f.read()
html = html.replace("<!--posts-->", "\n".join(posts_html))
with open(os.path.join(location, "saved.html"), "w") as f:
with open(os.path.join(location, html_file), "w") as f:
f.write(html)

View File

@ -20,6 +20,12 @@ def get_saved_posts(client):
yield saved
def get_upvoted_posts(client):
for upvoted in client.user.me().upvoted(limit=None):
if upvoted.__class__.__name__ == "Submission":
yield upvoted
def get_post_html(post):
with open(os.path.join("html", "post.html")) as f:
html = f.read()