Get upvoted posts
This commit is contained in:
parent
93225db543
commit
6a171ad2d5
10
html/upvoted.html
Normal file
10
html/upvoted.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Upvoted Posts</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Upvoted Posts</h1>
|
||||||
|
<!--posts-->
|
||||||
|
</body>
|
||||||
|
</html>
|
13
save.py
13
save.py
@ -19,17 +19,24 @@ if not os.path.isdir(location):
|
|||||||
# Make a client object
|
# Make a client object
|
||||||
client = make_client()
|
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 = []
|
posts_html = []
|
||||||
|
|
||||||
for post in get_saved_posts(client):
|
for post in get_posts(client):
|
||||||
posts_html.append(get_post_html(post))
|
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 = f.read()
|
||||||
|
|
||||||
html = html.replace("<!--posts-->", "\n".join(posts_html))
|
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)
|
f.write(html)
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,12 @@ def get_saved_posts(client):
|
|||||||
yield saved
|
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):
|
def get_post_html(post):
|
||||||
with open(os.path.join("html", "post.html")) as f:
|
with open(os.path.join("html", "post.html")) as f:
|
||||||
html = f.read()
|
html = f.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user