slimshadow commited on
Commit
2900a92
·
verified ·
1 Parent(s): 9f2fe87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,11 +1,19 @@
1
  import streamlit as st
2
  import feedparser
 
3
 
4
  # Function to fetch and parse RSS feed
5
  def fetch_rss_feed(url):
6
  feed = feedparser.parse(url)
7
  return feed.entries
8
 
 
 
 
 
 
 
 
9
  # RSS feed URL
10
  rss_url = "https://feeds.feedburner.com/ndtvnews-top-stories"
11
 
@@ -17,5 +25,23 @@ st.title("NDTV Top Stories")
17
 
18
  for entry in entries:
19
  st.subheader(entry.title)
20
- st.write(entry.summary)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  st.write(f"[Read more]({entry.link})")
 
1
  import streamlit as st
2
  import feedparser
3
+ from bs4 import BeautifulSoup
4
 
5
  # Function to fetch and parse RSS feed
6
  def fetch_rss_feed(url):
7
  feed = feedparser.parse(url)
8
  return feed.entries
9
 
10
+ # Function to extract images and text from HTML content
11
+ def extract_images_and_text(html_content):
12
+ soup = BeautifulSoup(html_content, 'html.parser')
13
+ images = [img['src'] for img in soup.find_all('img')]
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
 
 
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})")