Web / app1.py
nick5363's picture
Rename app.py to app1.py
4c224f6 verified
import requests
import feedparser
import gradio as gr
API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt"
def get_combined_news():
result = "\n\n"
index = 1
# VnExpress Kinh Doanh
try:
vnexpress_url = "https://vnexpress.net/rss/kinh-doanh.rss"
vn_feed = feedparser.parse(vnexpress_url)
for entry in vn_feed.entries[:5]:
result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
index += 1
except:
result += "*Lỗi khi lấy tin từ VnExpress*\n\n"
# Marketaux
try:
url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}"
data = requests.get(url).json()
for article in data.get("data", []):
title = article.get("title", "No title")
link = article.get("url", "#")
source = article.get("source", "Unknown")
published = article.get("published_at", "")
result += f"**{index}. [{title}]({link})** \n<sub>{source}{published}</sub>\n\n"
index += 1
except:
result += "*Lỗi khi lấy từ Marketaux*\n\n"
# Google RSS (Yahoo Finance)
try:
feed_url = "https://news.google.com/rss/search?q=site:finance.yahoo.com&hl=en-US&gl=US&ceid=US:en"
feed = feedparser.parse(feed_url)
for entry in feed.entries[:5]:
result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
index += 1
except:
result += "*Lỗi khi lấy từ Google RSS*\n\n"
return result
# Tự động load luôn khi mở web (live=True)
# Giao diện Gradio với theme tối + tự chạy
theme = gr.themes.Base().set(
body_background_fill="#000000", # nền đen
body_text_color="#ffffff", # chữ trắng
)
gr.Interface(
fn=get_combined_news,
inputs=None,
outputs="markdown",
live=True, # tự động chạy khi mở web
theme=theme,
).launch()