nickmuchi commited on
Commit
c8ec90e
·
verified ·
1 Parent(s): 0b918ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -27,28 +27,24 @@ def main():
27
  podcast_url = st.sidebar.text_input('Please paste the podcast RSS feed link here')
28
  latest_ep_button = st.sidebar.button("Get latest 5 Episodes")
29
 
30
- if latest_ep_button:
31
  try:
32
- # Extract the list of episodes for the given podcast
33
- podcast_feed = feedparser.parse(podcast_url)
34
- pods = {}
35
- num_episodes = min(len(podcast_feed.entries), 5)
 
 
 
36
 
37
- for pod in podcast_feed.entries[:num_episodes]:
38
- podcast_title = pod['title']
39
- podcast_image = pod.get('image', {}).get('href', '')
40
- episode_url = next((i['href'] for i in pod['links'] if i['type'] == 'audio/mpeg'), None)
41
- pods[podcast_title] = [episode_url, podcast_image]
42
-
43
- if pods:
44
  # Dropdown box
45
  st.sidebar.subheader("Available Podcasts Feeds")
46
- podcast_five_titles = ['Select an episode'] + list(pods.keys()) # Adding a placeholder at the beginning
47
- selected_podcast = st.sidebar.selectbox("Select Podcast", options=podcast_five_titles)
48
 
49
- # Check if the user has made a selection other than the placeholder
50
  if selected_podcast and selected_podcast != 'Select an episode':
51
- podcast_link, podcast_image = pods[selected_podcast]
52
 
53
  st.header("Newsletter Content")
54
 
 
27
  podcast_url = st.sidebar.text_input('Please paste the podcast RSS feed link here')
28
  latest_ep_button = st.sidebar.button("Get latest 5 Episodes")
29
 
30
+ if latest_ep_button or 'pods' in st.session_state:
31
  try:
32
+ if latest_ep_button:
33
+ # Parse the podcast feed and update session state
34
+ podcast_feed = feedparser.parse(podcast_url)
35
+ st.session_state['pods'] = {
36
+ pod['title']: [pod.get('links', [{}])[0].get('href', ''), pod.get('image', {}).get('href', '')]
37
+ for pod in podcast_feed.entries[:5]
38
+ }
39
 
40
+ if st.session_state['pods']:
 
 
 
 
 
 
41
  # Dropdown box
42
  st.sidebar.subheader("Available Podcasts Feeds")
43
+ podcast_titles = ['Select an episode'] + list(st.session_state['pods'].keys())
44
+ selected_podcast = st.sidebar.selectbox("Select Podcast", options=podcast_titles)
45
 
 
46
  if selected_podcast and selected_podcast != 'Select an episode':
47
+ podcast_link, podcast_image = st.session_state['pods'][selected_podcast]
48
 
49
  st.header("Newsletter Content")
50