slimshadow commited on
Commit
335bd01
·
verified ·
1 Parent(s): f5d7f4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ from xml.etree import ElementTree as ET
5
+
6
+ # Define RSS feed URLs
7
+ rss_feeds = {
8
+ "Top Stories": "http://timesofindia.indiatimes.com/rssfeedstopstories.cms",
9
+ "Most Recent Stories": "http://timesofindia.indiatimes.com/rssfeedmostrecent.cms",
10
+ "India": "http://timesofindia.indiatimes.com/rssfeeds/-2128936835.cms",
11
+ "World": "http://timesofindia.indiatimes.com/rssfeeds/296589292.cms",
12
+ "NRI": "http://timesofindia.indiatimes.com/rssfeeds/7098551.cms",
13
+ "Business": "http://timesofindia.indiatimes.com/rssfeeds/1898055.cms",
14
+ "US": "https://timesofindia.indiatimes.com/rssfeeds_us/72258322.cms",
15
+ "Cricket": "http://timesofindia.indiatimes.com/rssfeeds/54829575.cms",
16
+ "Sports": "http://timesofindia.indiatimes.com/rssfeeds/4719148.cms",
17
+ "Science": "http://timesofindia.indiatimes.com/rssfeeds/-2128672765.cms",
18
+ "Environment": "http://timesofindia.indiatimes.com/rssfeeds/2647163.cms",
19
+ "Tech": "http://timesofindia.indiatimes.com/rssfeeds/66949542.cms",
20
+ "Education": "http://timesofindia.indiatimes.com/rssfeeds/913168846.cms",
21
+ "Entertainment": "http://timesofindia.indiatimes.com/rssfeeds/1081479906.cms",
22
+ "Life & Style": "http://timesofindia.indiatimes.com/rssfeeds/2886704.cms",
23
+ "Most Read": "http://timesofindia.indiatimes.com/rssfeedmostread.cms",
24
+ "Most Shared": "http://timesofindia.indiatimes.com/rssfeedmostshared.cms",
25
+ "Most Commented": "http://timesofindia.indiatimes.com/rssfeedmostcommented.cms",
26
+ "Astrology": "https://timesofindia.indiatimes.com/rssfeeds/65857041.cms",
27
+ "Auto": "https://timesofindia.indiatimes.com/rssfeeds/74317216.cms"
28
+ }
29
+
30
+ def fetch_rss_feed(url):
31
+ response = requests.get(url)
32
+ response.raise_for_status()
33
+ root = ET.fromstring(response.content)
34
+ items = root.findall('.//item')
35
+ feed_data = []
36
+ for item in items:
37
+ title = item.find('title').text
38
+ link = item.find('link').text
39
+ description = item.find('description').text
40
+ pub_date = item.find('pubDate').text
41
+ feed_data.append({
42
+ 'title': title,
43
+ 'link': link,
44
+ 'description': description,
45
+ 'pub_date': pub_date
46
+ })
47
+ return feed_data
48
+
49
+ def main():
50
+ st.title("Times of India RSS Feeds")
51
+
52
+ # Sidebar navigation
53
+ section = st.sidebar.selectbox("Select a Section", list(rss_feeds.keys()))
54
+
55
+ # Fetch RSS feed data
56
+ feed_url = rss_feeds[section]
57
+ feed_data = fetch_rss_feed(feed_url)
58
+
59
+ # Display feed items
60
+ st.header(section)
61
+ for item in feed_data:
62
+ st.subheader(item['title'])
63
+ st.write(f"[Read more]({item['link']})")
64
+ st.write(item['description'])
65
+ st.write(f"*Published on {item['pub_date']}*")
66
+ st.write("---")
67
+
68
+ if __name__ == "__main__":
69
+ main()