Upload app_with_vnexpress.py
Browse files- app_with_vnexpress.py +48 -0
app_with_vnexpress.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import requests
|
| 3 |
+
import feedparser
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt"
|
| 7 |
+
|
| 8 |
+
def get_combined_news():
|
| 9 |
+
result = "\n\n"
|
| 10 |
+
index = 1
|
| 11 |
+
|
| 12 |
+
# Marketaux
|
| 13 |
+
try:
|
| 14 |
+
url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}"
|
| 15 |
+
data = requests.get(url).json()
|
| 16 |
+
for article in data.get("data", []):
|
| 17 |
+
title = article.get("title", "No title")
|
| 18 |
+
link = article.get("url", "#")
|
| 19 |
+
source = article.get("source", "Unknown")
|
| 20 |
+
published = article.get("published_at", "")
|
| 21 |
+
result += f"**{index}. [{title}]({link})** \n<sub>{source} – {published}</sub>\n\n"
|
| 22 |
+
index += 1
|
| 23 |
+
except:
|
| 24 |
+
result += "*Lỗi khi lấy từ Marketaux*\n\n"
|
| 25 |
+
|
| 26 |
+
# Google RSS (Yahoo Finance)
|
| 27 |
+
try:
|
| 28 |
+
feed_url = "https://news.google.com/rss/search?q=site:finance.yahoo.com&hl=en-US&gl=US&ceid=US:en"
|
| 29 |
+
feed = feedparser.parse(feed_url)
|
| 30 |
+
for entry in feed.entries[:5]:
|
| 31 |
+
result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
|
| 32 |
+
index += 1
|
| 33 |
+
except:
|
| 34 |
+
result += "*Lỗi khi lấy từ Google RSS*\n\n"
|
| 35 |
+
|
| 36 |
+
# VnExpress Kinh Doanh
|
| 37 |
+
try:
|
| 38 |
+
vnexpress_url = "https://vnexpress.net/rss/kinh-doanh.rss"
|
| 39 |
+
vn_feed = feedparser.parse(vnexpress_url)
|
| 40 |
+
for entry in vn_feed.entries[:5]:
|
| 41 |
+
result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
|
| 42 |
+
index += 1
|
| 43 |
+
except:
|
| 44 |
+
result += "*Lỗi khi lấy tin từ VnExpress*\n\n"
|
| 45 |
+
|
| 46 |
+
return result
|
| 47 |
+
|
| 48 |
+
gr.Interface(get_combined_news, inputs=[], outputs="markdown", title="Tin Tức Thị Trường Tổng Hợp").launch()
|