diff --git a/src/tool_use/tooluse/rss.py b/src/tool_use/tooluse/rss.py index 3cf971e..68805eb 100644 --- a/src/tool_use/tooluse/rss.py +++ b/src/tool_use/tooluse/rss.py @@ -14,13 +14,32 @@ 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): - 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,25 +117,38 @@ 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) - 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