diff --git a/src/classes/Twitter.py b/src/classes/Twitter.py index e9b3cc5..605a59a 100644 --- a/src/classes/Twitter.py +++ b/src/classes/Twitter.py @@ -85,11 +85,11 @@ class Twitter: bot.get("https://x.com/compose/post") - post_content: str = self.generate_post() + post_content: str = text if text is not None else self.generate_post() now: datetime = datetime.now() print(colored(" => Posting to Twitter:", "blue"), post_content[:30] + "...") - body = post_content if text is None else text + body = post_content text_box = None text_box_selectors = [ @@ -112,6 +112,7 @@ class Twitter: "Could not find tweet text box. Ensure you are logged into X in this Firefox profile." ) + post_button = None post_button_selectors = [ (By.XPATH, "//button[@data-testid='tweetButtonInline']"), @@ -135,9 +136,7 @@ class Twitter: time.sleep(2) # Add the post to the cache - self.add_post( - {"content": post_content, "date": now.strftime("%m/%d/%Y, %H:%M:%S")} - ) + self.add_post({"content": body, "date": now.strftime("%m/%d/%Y, %H:%M:%S")}) success("Posted to Twitter successfully!") diff --git a/src/utils.py b/src/utils.py index 76e9936..1b1f731 100644 --- a/src/utils.py +++ b/src/utils.py @@ -80,8 +80,14 @@ def fetch_songs() -> None: if get_verbose(): info(f" => Created directory: {files_dir}") else: - # Skip if songs are already downloaded - return + existing_audio_files = [ + name + for name in os.listdir(files_dir) + if os.path.isfile(os.path.join(files_dir, name)) + and name.lower().endswith((".mp3", ".wav", ".m4a", ".aac", ".ogg")) + ] + if len(existing_audio_files) > 0: + return configured_url = get_zip_url().strip() download_urls = [configured_url] if configured_url else [] @@ -144,5 +150,3 @@ def choose_random_song() -> str: except Exception as e: error(f"Error occurred while choosing random song: {str(e)}") raise - - raise RuntimeError("Failed to choose a random song")