Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 for Dainik Bhaskar
|
| 7 |
+
rss_feeds = {
|
| 8 |
+
"Opinion": "https://www.bhaskar.com/rss-v1--category-1944.xml",
|
| 9 |
+
"Budget 2024": "https://www.bhaskar.com/rss-v1--category-14994.xml",
|
| 10 |
+
"Bollywood": "https://www.bhaskar.com/rss-v1--category-11215.xml",
|
| 11 |
+
"Auto": "https://www.bhaskar.com/rss-v1--category-10711.xml",
|
| 12 |
+
"Jobs & Education": "https://www.bhaskar.com/rss-v1--category-11945.xml",
|
| 13 |
+
"Women": "https://www.bhaskar.com/rss-v1--category-1532.xml",
|
| 14 |
+
"Tech - Auto": "https://www.bhaskar.com/rss-v1--category-5707.xml",
|
| 15 |
+
"Happy Life": "https://www.bhaskar.com/rss-v1--category-7911.xml",
|
| 16 |
+
"Utility": "https://www.bhaskar.com/rss-v1--category-11616.xml",
|
| 17 |
+
"International": "https://www.bhaskar.com/rss-v1--category-1125.xml",
|
| 18 |
+
"National": "https://www.bhaskar.com/rss-v1--category-1061.xml",
|
| 19 |
+
"Business": "https://www.bhaskar.com/rss-v1--category-1051.xml",
|
| 20 |
+
"Sports": "https://www.bhaskar.com/rss-v1--category-1053.xml",
|
| 21 |
+
"Fake News Expose": "https://www.bhaskar.com/rss-v1--category-10891.xml",
|
| 22 |
+
"Magazine": "https://www.bhaskar.com/rss-v1--category-1057.xml",
|
| 23 |
+
"Jeevan Mantra": "https://www.bhaskar.com/rss-v1--category-3379.xml",
|
| 24 |
+
"Entertainment": "https://www.bhaskar.com/rss-v1--category-3998.xml",
|
| 25 |
+
"DB Original": "https://www.bhaskar.com/rss-v1--category-4587.xml",
|
| 26 |
+
"Rajasthan": "https://www.bhaskar.com/rss-v1--category-1740.xml",
|
| 27 |
+
"Madhya Pradesh": "https://www.bhaskar.com/rss-v1--category-1739.xml",
|
| 28 |
+
"Uttar Pradesh": "https://www.bhaskar.com/rss-v1--category-2052.xml",
|
| 29 |
+
"Bihar": "https://www.bhaskar.com/rss-v1--category-3679.xml",
|
| 30 |
+
"Chhattisgarh": "https://www.bhaskar.com/rss-v1--category-1741.xml",
|
| 31 |
+
"Haryana": "https://www.bhaskar.com/rss-v1--category-1742.xml",
|
| 32 |
+
"New Delhi": "https://www.bhaskar.com/rss-v1--category-7140.xml",
|
| 33 |
+
"Maharashtra": "https://www.bhaskar.com/rss-v1--category-2318.xml",
|
| 34 |
+
"Jharkhand": "https://www.bhaskar.com/rss-v1--category-3682.xml",
|
| 35 |
+
"Punjab": "https://www.bhaskar.com/rss-v1--category-1743.xml",
|
| 36 |
+
"Gujarat": "https://www.bhaskar.com/rss-v1--category-2314.xml",
|
| 37 |
+
"Chandigarh": "https://www.bhaskar.com/rss-v1--category-11649.xml",
|
| 38 |
+
"Himachal": "https://www.bhaskar.com/rss-v1--category-12084.xml",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
def fetch_rss_feed(url):
|
| 42 |
+
response = requests.get(url)
|
| 43 |
+
response.raise_for_status()
|
| 44 |
+
root = ET.fromstring(response.content)
|
| 45 |
+
|
| 46 |
+
# Extract channel-wide image URL
|
| 47 |
+
channel_image = root.find('.//image/url')
|
| 48 |
+
channel_image_url = channel_image.text if channel_image is not None else None
|
| 49 |
+
|
| 50 |
+
items = root.findall('.//item')
|
| 51 |
+
feed_data = []
|
| 52 |
+
|
| 53 |
+
for item in items:
|
| 54 |
+
title = item.find('title').text
|
| 55 |
+
link = item.find('link').text
|
| 56 |
+
description = item.find('description')
|
| 57 |
+
pub_date = item.find('pubDate').text
|
| 58 |
+
media_content = item.find('{http://search.yahoo.com/mrss/}content')
|
| 59 |
+
|
| 60 |
+
# Handle cases where description might be None
|
| 61 |
+
description_text = BeautifulSoup(description.text, 'html.parser').get_text() if description is not None and description.text else "No description available"
|
| 62 |
+
|
| 63 |
+
# Extract image URL from media content or fallback to channel image
|
| 64 |
+
image_url = media_content.attrib['url'] if media_content is not None and 'url' in media_content.attrib else channel_image_url
|
| 65 |
+
|
| 66 |
+
feed_data.append({
|
| 67 |
+
'title': title,
|
| 68 |
+
'link': link,
|
| 69 |
+
'description': description_text,
|
| 70 |
+
'pub_date': pub_date,
|
| 71 |
+
'image': image_url
|
| 72 |
+
})
|
| 73 |
+
return feed_data
|
| 74 |
+
|
| 75 |
+
def main():
|
| 76 |
+
st.title("Dainik Bhaskar RSS Feeds")
|
| 77 |
+
|
| 78 |
+
# Sidebar navigation
|
| 79 |
+
section = st.sidebar.selectbox("Select a Section", list(rss_feeds.keys()))
|
| 80 |
+
|
| 81 |
+
# Fetch RSS feed data
|
| 82 |
+
feed_url = rss_feeds[section]
|
| 83 |
+
feed_data = fetch_rss_feed(feed_url)
|
| 84 |
+
|
| 85 |
+
# Display feed items
|
| 86 |
+
st.header(f"{section}")
|
| 87 |
+
for item in feed_data:
|
| 88 |
+
st.subheader(item['title'])
|
| 89 |
+
st.write(f"[Read more]({item['link']})")
|
| 90 |
+
|
| 91 |
+
# Display image if present
|
| 92 |
+
if item['image']:
|
| 93 |
+
st.image(item['image'])
|
| 94 |
+
|
| 95 |
+
st.write(item['description'])
|
| 96 |
+
st.write(f"*Published on {item['pub_date']}*")
|
| 97 |
+
st.write("---")
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
main()
|