diff --git a/main.py b/main.py index 1666f17..d87b4fe 100755 --- a/main.py +++ b/main.py @@ -1,18 +1,18 @@ #!/usr/bin/env python from subprocess import Popen -from dotenv import load_dotenv from os import getenv, name +from dotenv import load_dotenv from reddit.subreddit import get_subreddit_threads from utils.cleanup import cleanup from utils.console import print_markdown, print_step +from utils.checker import check_env # from utils.checker import envUpdate from video_creation.background import download_background, chop_background_video from video_creation.final_video import make_final_video from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.voices import save_text_to_mp3 -from utils.checker import check_env VERSION = 2.1 print( diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 98bf8a1..cc36fc3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -2,11 +2,11 @@ import re from os import getenv, environ import praw +from praw.models import MoreComments from utils.console import print_step, print_substep from utils.subreddit import get_subreddit_undone from utils.videos import check_done -from praw.models import MoreComments TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890") @@ -26,7 +26,9 @@ def get_subreddit_threads(): """ Returns a list of threads from the AskReddit subreddit. """ - global submission + + submission = None + print_substep("Logging into Reddit.") content = {} @@ -48,9 +50,8 @@ def get_subreddit_threads(): passkey=passkey, check_for_async=False, ) - """ - Ask user for subreddit input - """ + + # Ask user for subreddit input print_step("Getting subreddit threads...") if not getenv( "SUBREDDIT" @@ -89,9 +90,7 @@ def get_subreddit_threads(): print_substep(f"Thread has {upvotes} upvotes", style="bold blue") print_substep(f"Thread has a upvote ratio of {ratio}%", style="bold blue") print_substep(f"Thread has {num_comments} comments", style="bold blue") - environ["VIDEO_TITLE"] = str( - textify(submission.title) - ) # todo use global instend of env vars + environ["VIDEO_TITLE"] = str(textify(submission.title)) environ["VIDEO_ID"] = str(textify(submission.id)) content["thread_url"] = f"https://reddit.com{submission.permalink}" @@ -105,7 +104,7 @@ def get_subreddit_threads(): continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 if not top_level_comment.stickied: if len(top_level_comment.body) <= int(try_env("MAX_COMMENT_LENGTH", 500)): - if not top_level_comment.author == None: + if not top_level_comment.author is None: content["comments"].append( { "comment_body": top_level_comment.body, diff --git a/setup.py b/setup.py index e3cae6d..5aab956 100755 --- a/setup.py +++ b/setup.py @@ -5,11 +5,10 @@ # Imports import os import subprocess -import re -from utils.console import print_markdown -from utils.console import print_step from rich.console import Console from utils.loader import Loader +from utils.console import print_markdown +from utils.console import print_step from utils.console import handle_input console = Console() diff --git a/utils/subreddit.py b/utils/subreddit.py index 94de416..ac684cb 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -1,4 +1,3 @@ -from typing import List import json from os import getenv from utils.console import print_substep @@ -14,9 +13,8 @@ def get_subreddit_undone(submissions: list, subreddit): Returns: Any: The submission that has not been done """ - """ - recursively checks if the top submission in the list was already done. - """ + # recursively checks if the top submission in the list was already done. + with open( "./video_creation/data/videos.json", "r", encoding="utf-8" ) as done_vids_raw: diff --git a/utils/voice.py b/utils/voice.py index e78ddad..c4f27bf 100644 --- a/utils/voice.py +++ b/utils/voice.py @@ -2,7 +2,7 @@ import re def sanitize_text(text: str) -> str: - """Sanitizes the text for tts. + r"""Sanitizes the text for tts. What gets removed: - following characters`^_~@!&;#:-%“”‘"%*/{}[]()\|<>?=+` - any http or https links diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 83dd4c6..b4df787 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,19 +1,17 @@ import json -from os import getenv import os +from os import getenv from pathlib import Path -from playwright.async_api import async_playwright # do not remove this line -from playwright.sync_api import sync_playwright, ViewportSize -from rich.progress import track +from playwright.async_api import async_playwright # pylint: disable=unused-import -from utils.console import print_step, print_substep -import json -from rich.console import Console +# do not remove the above line +from playwright.sync_api import sync_playwright, ViewportSize +from rich.progress import track import translators as ts -console = Console() +from utils.console import print_step, print_substep storymode = False