File size: 3,393 Bytes
5f45fb9
 
2900a92
5f45fb9
9f2fe87
5f45fb9
9f2fe87
 
5f45fb9
2900a92
 
 
 
 
 
 
86c3aae
 
 
 
 
 
 
 
 
 
 
 
9f280a3
86c3aae
 
 
 
 
 
 
 
 
 
 
 
 
 
d6895c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47a5a9b
d6895c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86c3aae
 
2900a92
86c3aae
 
2900a92
86c3aae
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import streamlit as st
import feedparser
from bs4 import BeautifulSoup

# Function to fetch and parse RSS feed
def fetch_rss_feed(url):
    feed = feedparser.parse(url)
    return feed.entries

# Function to extract images and text from HTML content
def extract_images_and_text(html_content):
    soup = BeautifulSoup(html_content, 'html.parser')
    images = [img['src'] for img in soup.find_all('img')]
    text = soup.get_text()
    return images, text

# Function to display RSS feed content
def display_feed(feed_url):
    entries = fetch_rss_feed(feed_url)
    for entry in entries:
        st.subheader(entry.title)
        st.write(f"Published on: {entry.published}")

        # Check for media content
        media_content = entry.get('media_content', [])
        if media_content:
            for media in media_content:
                if media.get('url'):
                    st.image(media['url'], width=300)  # Display image

        # Use BeautifulSoup to parse HTML content
        content_encoded = entry.get('content_encoded', entry.description)
        images, text = extract_images_and_text(content_encoded)
        st.write(text)  # Display plain text
        
        for img_url in images:
            st.image(img_url, width=600)  # Display images if any

        st.write(f"[Read more]({entry.link})")

# Main function to handle Streamlit app
def main():
    st.sidebar.title("Navigation")
    selection = st.sidebar.radio("Choose a section", [
        "Latest Stories", 
        "Top Stories", 
        "World", 
        "Movies", 
        "Tech", 
        "Trending News",
        "India News",
        "Sports",
        "Cricket",
        "Car & Bike",
        "Cities News",
        "South",
        "Indians Abroad",
        "Cooks",
        "Offbeat News",
        "People",
        "NDTV Khabar",
        "Latest Videos"
    ])

    # Define RSS feed URLs for different sections
    feed_urls = {
        "Latest Stories": "https://feeds.feedburner.com/ndtvnews-latest",
        "Top Stories": "https://feeds.feedburner.com/ndtvnews-top-stories",
        "World": "https://feeds.feedburner.com/ndtvnews-world-news",
        "Movies": "https://feeds.feedburner.com/ndtvmovies-latest",
        "Tech": "https://feeds.feedburner.com/gadgets360-latest",
        "Trending News": "https://feeds.feedburner.com/ndtvnews-trending-news",
        "India News": "https://feeds.feedburner.com/ndtvnews-india-news",
        "Sports": "https://feeds.feedburner.com/ndtvsports-latest",
        "Cricket": "https://feeds.feedburner.com/ndtvsports-cricket",
        "Car & Bike": "https://feeds.feedburner.com/carandbike-latest",
        "Cities News": "https://feeds.feedburner.com/ndtvnews-cities-news",
        "South": "https://feeds.feedburner.com/ndtvnews-south",
        "Indians Abroad": "https://feeds.feedburner.com/ndtvnews-indians-abroad",
        "Cooks": "https://feeds.feedburner.com/ndtvcooks-latest",
        "Offbeat News": "https://feeds.feedburner.com/ndtvnews-offbeat-news",
        "People": "https://feeds.feedburner.com/ndtvnews-people",
        "NDTV Khabar": "https://feeds.feedburner.com/ndtvkhabar-latest",
        "Latest Videos": "https://feeds.feedburner.com/ndtv/latest-videos"
    }

    feed_url = feed_urls.get(selection)
    
    st.title(f"NDTV {selection}")
    display_feed(feed_url)

# Run the app
if __name__ == "__main__":
    main()