Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty episode table in 'tooluse' command #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions src/tool_use/tooluse/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()