Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
from pygooglenews import GoogleNews
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Function to fetch top stories related to a specific topic
|
| 9 |
-
def fetch_top_stories(topic, language='de', country='GER'):
|
| 10 |
-
gn = GoogleNews(lang=language, country=country)
|
| 11 |
-
search_results = gn.search(topic)
|
| 12 |
-
|
| 13 |
-
top_stories = []
|
| 14 |
-
for story in search_results['entries']:
|
| 15 |
-
story_data = {
|
| 16 |
-
'title': story.title,
|
| 17 |
-
'link': story.link,
|
| 18 |
-
'published': story.published
|
| 19 |
-
}
|
| 20 |
-
top_stories.append(story_data)
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
# Define the page for trending niche news
|
| 25 |
def page_trending_niche():
|
| 26 |
col1, col2 = st.columns([3, 1])
|
| 27 |
with col1:
|
|
@@ -29,13 +23,15 @@ def page_trending_niche():
|
|
| 29 |
with col2:
|
| 30 |
st.image('Robot.png', use_column_width=True)
|
| 31 |
|
| 32 |
-
niche = st.text_input('Enter your niche', '
|
| 33 |
if niche:
|
| 34 |
-
news_items =
|
| 35 |
for item in news_items:
|
| 36 |
st.write(f"**Title:** {item['title']}")
|
| 37 |
-
st.write(f"**
|
| 38 |
-
st.write(f"**
|
|
|
|
|
|
|
| 39 |
st.write("---")
|
| 40 |
|
| 41 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from gnews import GNews
|
|
|
|
| 3 |
|
| 4 |
+
def fetch_news(topic):
|
| 5 |
+
google_news = GNews(language='en', country='US') # You can customize this
|
| 6 |
+
news_list = google_news.get_news(topic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
articles = []
|
| 9 |
+
for news in news_list[:5]: # Get top 5 news articles
|
| 10 |
+
articles.append({
|
| 11 |
+
'title': news['title'],
|
| 12 |
+
'published_date': news['published date'],
|
| 13 |
+
'description': news['description'],
|
| 14 |
+
'url': news['url'],
|
| 15 |
+
'publisher': news['publisher']
|
| 16 |
+
})
|
| 17 |
+
return articles
|
| 18 |
|
|
|
|
| 19 |
def page_trending_niche():
|
| 20 |
col1, col2 = st.columns([3, 1])
|
| 21 |
with col1:
|
|
|
|
| 23 |
with col2:
|
| 24 |
st.image('Robot.png', use_column_width=True)
|
| 25 |
|
| 26 |
+
niche = st.text_input('Enter your niche', 'Technology')
|
| 27 |
if niche:
|
| 28 |
+
news_items = fetch_news(niche)
|
| 29 |
for item in news_items:
|
| 30 |
st.write(f"**Title:** {item['title']}")
|
| 31 |
+
st.write(f"**Published Date:** {item['published_date']}")
|
| 32 |
+
st.write(f"**Description:** {item['description']}")
|
| 33 |
+
st.write(f"**Publisher:** {item['publisher']}")
|
| 34 |
+
st.write(f"**URL:** [Read more]({item['url']})")
|
| 35 |
st.write("---")
|
| 36 |
|
| 37 |
|