Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 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 |
-
|
| 47 |
-
selected_podcast = st.sidebar.selectbox("Select Podcast", options=
|
| 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 |
|