From 6cbaf449017d2df2db9c91ddc063a60e092ad064 Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Tue, 12 Nov 2024 01:33:32 +0000 Subject: [PATCH 1/2] Improve error handling and user feedback in RSS feed parsing and playback The changes in this commit improve the error handling and user feedback in the RSS feed parsing and playback functionality of the tool. Specifically: 1. The `fetch_rss_feed` function now checks if the feed is in a "bozo" state (i.e., there was an error parsing the feed) and prints a clear error message if that's the case. 2. The `display_episodes` function now checks if the feed has any entries and prints a message if there are none. 3. The `play_mp3` function now provides more detailed debug information if the audio playback fails, including a suggestion to check the RSS feed URL and internet connection. 4. The `main` function now checks if the feed is valid and has entries before proceeding with the main loop, and prints a message if there are no episodes found. These improvements should help users better understand what went wrong if there are issues with the RSS feed or audio playback, and provide them with more guidance on how to troubleshoot the problem. --- src/tool_use/tooluse/rss.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tool_use/tooluse/rss.py b/src/tool_use/tooluse/rss.py index 3cf971e..d307077 100644 --- a/src/tool_use/tooluse/rss.py +++ b/src/tool_use/tooluse/rss.py @@ -18,9 +18,16 @@ console = Console() def fetch_rss_feed(url): - return feedparser.parse(url) + feed = feedparser.parse(url) + if feed.bozo: + console.print("[bold red]Error:[/bold red] Failed to parse RSS feed.") + return None + return feed def display_episodes(feed): + if not feed.entries: + console.print("[bold yellow]No episodes available to display.[/bold yellow]") + return table = Table(title="Podcast Episodes", box=box.ROUNDED) table.add_column("Title", style="cyan", no_wrap=True) table.add_column("Date", style="magenta") @@ -98,10 +105,14 @@ def play_mp3(url): console.print("[bold red]Error:[/bold red] Could not play audio. Please install either:") console.print("- sounddevice and soundfile (pip install sounddevice soundfile)") console.print("- mpv (system package)") + console.print("[bold red]Debug Info:[/bold red] Ensure the RSS feed URL is correct and accessible.") def main(): rss_url = "https://anchor.fm/s/fb2a98a0/podcast/rss" feed = fetch_rss_feed(rss_url) + if not feed or not feed.entries: + console.print("[bold yellow]No episodes found. Please check the RSS feed URL or your internet connection.[/bold yellow]") + return while True: console.clear() From 831c54659f595b7d88d82d496d0b4248bee37c9f Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:08:27 +0000 Subject: [PATCH 2/2] Add contact functionality to Tool Use podcast player The commit message should be: Add contact functionality to Tool Use podcast player This change adds a new option to the main menu of the Tool Use podcast player, allowing users to contact the podcast creators. The new "Contact Tool Use" option calls the `contact.main()` function, which presumably handles the contact functionality. Additionally, the code has been refactored to better organize the main loop and handle the different options (podcast, contact, exit) more cleanly. --- src/tool_use/tooluse/rss.py | 55 +++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/tool_use/tooluse/rss.py b/src/tool_use/tooluse/rss.py index d307077..68805eb 100644 --- a/src/tool_use/tooluse/rss.py +++ b/src/tool_use/tooluse/rss.py @@ -14,9 +14,21 @@ import soundfile as sf import io import requests +from . import contact console = Console() +def select_main_option(): + choices = [inquirer.List('option', + message="What would you like to do?", + choices=[ + ('Listen to Tool Use Podcast', 'podcast'), + ('Contact Tool Use', 'contact'), + ('Exit', 'exit') + ])] + result = inquirer.prompt(choices) + return result['option'] if result else 'exit' + def fetch_rss_feed(url): feed = feedparser.parse(url) if feed.bozo: @@ -108,26 +120,35 @@ def play_mp3(url): console.print("[bold red]Debug Info:[/bold red] Ensure the RSS feed URL is correct and accessible.") def main(): - rss_url = "https://anchor.fm/s/fb2a98a0/podcast/rss" - feed = fetch_rss_feed(rss_url) - if not feed or not feed.entries: - console.print("[bold yellow]No episodes found. Please check the RSS feed URL or your internet connection.[/bold yellow]") - return - while True: console.clear() - display_episodes(feed) - episode = select_episode(feed) - - if episode is None: + option = select_main_option() + + if option == 'exit': break + elif option == 'contact': + contact.main() + else: # podcast option + rss_url = "https://anchor.fm/s/fb2a98a0/podcast/rss" + feed = fetch_rss_feed(rss_url) + if not feed or not feed.entries: + console.print("[bold yellow]No episodes found. Please check the RSS feed URL or your internet connection.[/bold yellow]") + continue + + while True: + console.clear() + display_episodes(feed) + episode = select_episode(feed) + + if episode is None: + break - while True: - console.clear() - display_episode_options(episode) - option = prompt("Enter your choice (1-5): ") - if handle_option(episode, option): - break + while True: + console.clear() + display_episode_options(episode) + option = prompt("Enter your choice (1-5): ") + if handle_option(episode, option): + break if __name__ == "__main__": - main() + main() \ No newline at end of file