slimshadow commited on
Commit
86c3aae
·
verified ·
1 Parent(s): 7532d70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -29
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 URL
18
- rss_url = "https://feeds.feedburner.com/ndtvnews-top-stories"
19
-
20
- # Fetch RSS feed
21
- entries = fetch_rss_feed(rss_url)
22
-
23
- # Streamlit App
24
- st.title("NDTV Top Stories")
25
-
26
- for entry in entries:
27
- st.subheader(entry.title)
28
-
29
- # Display publication date
30
- st.write(f"Published on: {entry.published}")
31
-
32
- # Check for media content
33
- media_content = entry.get('media_content', [])
34
- if media_content:
35
- for media in media_content:
36
- if media.get('url'):
37
- st.image(media['url'], width=600) # Display image
38
-
39
- # Use BeautifulSoup to parse HTML content
40
- content_encoded = entry.get('content_encoded', entry.description)
41
- images, text = extract_images_and_text(content_encoded)
42
- st.write(text) # Display plain text
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- for img_url in images:
45
- st.image(img_url, width=600) # Display images if any
46
 
47
- st.write(f"[Read more]({entry.link})")
 
 
 
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()