Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,34 +14,48 @@ def extract_images_and_text(html_content):
|
|
| 14 |
text = soup.get_text()
|
| 15 |
return images, text
|
| 16 |
|
| 17 |
-
# RSS feed
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
| 14 |
text = soup.get_text()
|
| 15 |
return images, text
|
| 16 |
|
| 17 |
+
# Function to display RSS feed content
|
| 18 |
+
def display_feed(feed_url):
|
| 19 |
+
entries = fetch_rss_feed(feed_url)
|
| 20 |
+
for entry in entries:
|
| 21 |
+
st.subheader(entry.title)
|
| 22 |
+
st.write(f"Published on: {entry.published}")
|
| 23 |
+
|
| 24 |
+
# Check for media content
|
| 25 |
+
media_content = entry.get('media_content', [])
|
| 26 |
+
if media_content:
|
| 27 |
+
for media in media_content:
|
| 28 |
+
if media.get('url'):
|
| 29 |
+
st.image(media['url'], width=600) # Display image
|
| 30 |
+
|
| 31 |
+
# Use BeautifulSoup to parse HTML content
|
| 32 |
+
content_encoded = entry.get('content_encoded', entry.description)
|
| 33 |
+
images, text = extract_images_and_text(content_encoded)
|
| 34 |
+
st.write(text) # Display plain text
|
| 35 |
+
|
| 36 |
+
for img_url in images:
|
| 37 |
+
st.image(img_url, width=600) # Display images if any
|
| 38 |
+
|
| 39 |
+
st.write(f"[Read more]({entry.link})")
|
| 40 |
+
|
| 41 |
+
# Main function to handle Streamlit app
|
| 42 |
+
def main():
|
| 43 |
+
st.sidebar.title("Navigation")
|
| 44 |
+
selection = st.sidebar.radio("Choose a section", ["Top Stories", "World", "Movies", "Tech"])
|
| 45 |
+
|
| 46 |
+
# Define RSS feed URLs for different sections
|
| 47 |
+
feed_urls = {
|
| 48 |
+
"Top Stories": "https://feeds.feedburner.com/ndtvnews-top-stories",
|
| 49 |
+
"World": "https://feeds.feedburner.com/ndtvnews-world-news",
|
| 50 |
+
"Movies": "https://feeds.feedburner.com/ndtvmovies-latest",
|
| 51 |
+
"Tech": "https://feeds.feedburner.com/gadgets360-latest"
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
feed_url = feed_urls.get(selection)
|
| 55 |
|
| 56 |
+
st.title(f"NDTV {selection}")
|
| 57 |
+
display_feed(feed_url)
|
| 58 |
|
| 59 |
+
# Run the app
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
main()
|