fix: refactor fixing

pull/283/head
orenkaizer 3 years ago
parent 849a84e1a4
commit 26f597480b

@ -25,12 +25,15 @@ def startup_config():
def main():
startup_config()
reddit_object = get_subreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME"))
download_background()
chop_background_video(length)
make_final_video(number_of_comments)
main()

@ -27,12 +27,8 @@ def get_subreddit_threads():
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:")
content = { 'thread_url': submission.url, 'thread_title': submission.title }
content["comments"] = [{
"comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id,
} for top_level_comment in submission.comments]
content = build_content_comments(submission)
print_substep("Received AskReddit threads successfully.", style="bold green")
@ -68,3 +64,22 @@ def choose_subreddit(reddit):
print_substep("Subreddit not defined. Using AskReddit.")
return subreddit
def build_content_comments(submission):
try:
content = { 'thread_url': submission.url, 'thread_title': submission.title }
content["comments"] = []
for top_level_comment in submission.comments:
content["comments"].append(
{
"comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id,
}
)
except AttributeError as e:
pass
return content

@ -20,7 +20,8 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
with sync_playwright() as p:
print_substep("Launching Headless Browser...")
browser, context = p.chromium.launch(), browser.new_context()
browser = p.chromium.launch()
context = browser.new_context()
page = context.new_page()
if theme.casefold() == "dark":

Loading…
Cancel
Save