File size: 2,072 Bytes
bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 9910815 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 19a5c1b bad1245 |
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 |
import requests
import feedparser
import gradio as gr
# API Key Marketaux
API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt"
# Hàm lấy tin từ Marketaux (3 bài)
def get_marketaux_news():
url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}"
try:
response = requests.get(url)
if response.status_code != 200:
return f"Lỗi API Marketaux: {response.status_code}\n{response.text}"
data = response.json()
news_list = data.get("data", [])
except Exception as e:
return f"Lỗi gọi Marketaux: {str(e)}"
result = "## [Marketaux] Tin Tài chính Real-time (3 bài)\n\n"
for i, article in enumerate(news_list):
title = article.get("title", "Không có tiêu đề")
link = article.get("url", "#")
source = article.get("source", "Unknown")
published = article.get("published_at", "")
result += f"**{i+1}. [{title}]({link})** \n<sub>{source} – {published}</sub>\n\n"
return result
# Hàm lấy tin từ Google News RSS (Yahoo Finance)
def get_google_news():
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)
if not feed.entries:
return "Không có tin từ Google RSS."
result = "## [Google News] Tin tức Yahoo Finance (7 bài)\n\n"
for i, entry in enumerate(feed.entries[:7]):
title = entry.title
link = entry.link
published = entry.published
result += f"**{i+1}. [{title}]({link})** \n<sub>{published}</sub>\n\n"
return result
# Hàm kết hợp
def show_combined_news():
m_news = get_marketaux_news()
g_news = get_google_news()
return f"{m_news}\n\n---\n\n{g_news}"
# Giao diện
gr.Interface(
fn=show_combined_news,
inputs=None,
outputs="markdown",
title="Tin tức Tài chính Mới nhất (Marketaux + Yahoo RSS)",
description="Hiển thị 3 tin real-time từ Marketaux + 7 tin từ Yahoo Finance (Google RSS)."
).launch() |