Fix small bugs and path issues

pull/653/head
Callum Leslie 3 years ago
parent c58fa10f53
commit 7765c9b018

@ -28,7 +28,7 @@ class TTSEngine:
self, self,
tts_module, tts_module,
reddit_object: dict, reddit_object: dict,
path: str = "assets/mp3", path: str = "assets/temp/mp3",
max_length: int = 50, max_length: int = 50,
): ):
self.tts_module = tts_module() self.tts_module = tts_module()
@ -54,7 +54,6 @@ class TTSEngine:
self.reddit_object["thread_post"] != "" self.reddit_object["thread_post"] != ""
and getenv("STORYMODE", "").casefold() == "true" and getenv("STORYMODE", "").casefold() == "true"
): ):
self.call_tts("posttext", sanitize_text(self.reddit_object["thread_post"])) self.call_tts("posttext", sanitize_text(self.reddit_object["thread_post"]))
idx = None idx = None

@ -31,7 +31,9 @@ def get_subreddit_threads():
content = {} content = {}
if str(getenv("REDDIT_2FA")).casefold() == "yes": if str(getenv("REDDIT_2FA")).casefold() == "yes":
print("\nEnter your two-factor authentication code from your authenticator app.\n") print(
"\nEnter your two-factor authentication code from your authenticator app.\n"
)
code = input("> ") code = input("> ")
print() print()
pw = getenv("REDDIT_PASSWORD") pw = getenv("REDDIT_PASSWORD")
@ -55,14 +57,18 @@ def get_subreddit_threads():
): # note to user. you can have multiple subreddits via reddit.subreddit("redditdev+learnpython") ): # note to user. you can have multiple subreddits via reddit.subreddit("redditdev+learnpython")
try: try:
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) re.sub(
r"r\/", "", input("What subreddit would you like to pull from? ")
)
# removes the r/ from the input # removes the r/ from the input
) )
except ValueError: except ValueError:
subreddit = reddit.subreddit("askreddit") subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.") print_substep("Subreddit not defined. Using AskReddit.")
else: else:
print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config") print_substep(
f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config"
)
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
getenv("SUBREDDIT") getenv("SUBREDDIT")
) # Allows you to specify in .env. Done for automation purposes. ) # Allows you to specify in .env. Done for automation purposes.
@ -83,12 +89,14 @@ def get_subreddit_threads():
print_substep(f"Thread has {upvotes} upvotes", style="bold blue") 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 a upvote ratio of {ratio}%", style="bold blue")
print_substep(f"Thread has {num_comments} comments", 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)
) # todo use global instend of env vars
environ["VIDEO_ID"] = str(textify(submission.id)) environ["VIDEO_ID"] = str(textify(submission.id))
content["thread_url"] = f"https://reddit.com{submission.permalink}" content["thread_url"] = f"https://reddit.com{submission.permalink}"
content["thread_title"] = submission.title content["thread_title"] = submission.title
# content["thread_content"] = submission.content content["thread_post"] = submission.selftext
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if isinstance(top_level_comment, MoreComments): if isinstance(top_level_comment, MoreComments):

@ -17,6 +17,6 @@ def sanitize_text(text):
# note: not removing apostrophes # note: not removing apostrophes
regex_expr = r"\s['|]|['|]\s|[\^_~@!&;#:\-%“”‘\"%\*/{}\[\]\(\)\\|<>=+]" regex_expr = r"\s['|]|['|]\s|[\^_~@!&;#:\-%“”‘\"%\*/{}\[\]\(\)\\|<>=+]"
result = re.sub(regex_expr, " ", result) result = re.sub(regex_expr, " ", result)
result = result.replace("+", "plus").replace(" ", "+").replace("&", "and") result = result.replace("+", "plus").replace("&", "and")
# remove extra whitespace # remove extra whitespace
return " ".join(result.split()) return " ".join(result.split())

@ -1 +1,9 @@
[] [
{
"id": "vfxpph",
"time": "1655671664",
"background_credit": "bbswitzer",
"reddit_title": "What unimpressive things are people idiotically proud of",
"filename": "What unimpressive things are p....mp4"
}
]
Loading…
Cancel
Save