From d095391d352bbae66153c2417e5a3042e2acb646 Mon Sep 17 00:00:00 2001 From: PatatjeMC Date: Sun, 5 Jun 2022 22:36:55 +0200 Subject: [PATCH] Error fix Moved the character limit checker cause it was being buggy and making it so some longer comments went thru but not others and it looks like that's fixed now also deleted another character limit check cause it wasn't needed anymore. and for some reason the text replace thingy was in an if statement even tho I don't think it should have been in there. --- main.py | 3 --- reddit/subreddit.py | 7 ++++--- video_creation/TTSwrapper.py | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 10be90b..4aa0a4b 100755 --- a/main.py +++ b/main.py @@ -19,9 +19,6 @@ def main(): def get_obj(): reddit_obj = get_subreddit_threads() - for comment in (reddit_obj["comments"]): - if len(comment["comment_body"]) > 250: - reddit_obj["comments"].remove(comment) return reddit_obj reddit_object = get_obj() diff --git a/reddit/subreddit.py b/reddit/subreddit.py index ff19334..c2a59df 100755 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -58,9 +58,10 @@ def get_subreddit_threads(): 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, }) + if len(top_level_comment.body) <= 250: + 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 diff --git a/video_creation/TTSwrapper.py b/video_creation/TTSwrapper.py index e239e81..0b50b15 100644 --- a/video_creation/TTSwrapper.py +++ b/video_creation/TTSwrapper.py @@ -54,10 +54,7 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper self.URI_BASE = 'https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=' def tts(self, req_text: str = "TikTok Text To Speech", filename: str = 'title.mp3', random_speaker: bool = False): - if len(req_text) > 299: - return ValueError("Text too long must be under 299 characters") - if random_speaker: - req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") + req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") voice = self.randomvoice() if random_speaker else 'en_us_002' r = requests.post(f"{self.URI_BASE}{voice}&req_text={req_text}&speaker_map_type=0")