Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
API_KEY = "A3WuGPFo3tqoY2CDWs1JP27K1nrtx8nWdi4053Jt"
|
| 5 |
+
|
| 6 |
+
def get_marketaux_news():
|
| 7 |
+
url = f"https://api.marketaux.com/v1/news/all?language=en&limit=5&api_token={API_KEY}"
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
response = requests.get(url)
|
| 11 |
+
data = response.json()
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"Lỗi khi gọi Marketaux API: {e}"
|
| 14 |
+
|
| 15 |
+
if "data" not in data or len(data["data"]) == 0:
|
| 16 |
+
return "Không có tin tức mới nào từ Marketaux."
|
| 17 |
+
|
| 18 |
+
result = "# Tin tức Tài chính Mới nhất (Marketaux API)\n\n"
|
| 19 |
+
for i, article in enumerate(data["data"][:5]):
|
| 20 |
+
title = article.get("title", "Không có tiêu đề")
|
| 21 |
+
url = article.get("url", "#")
|
| 22 |
+
source = article.get("source", {}).get("name", "Unknown")
|
| 23 |
+
published = article.get("published_at", "")
|
| 24 |
+
result += f"**{i+1}. [{title}]({url})** \n<sub>{source} – {published}</sub>\n\n"
|
| 25 |
+
|
| 26 |
+
return result
|
| 27 |
+
|
| 28 |
+
gr.Interface(
|
| 29 |
+
fn=get_marketaux_news,
|
| 30 |
+
inputs=None,
|
| 31 |
+
outputs="markdown",
|
| 32 |
+
title="Tin tức Tài chính Mới nhất (Marketaux API)",
|
| 33 |
+
description="Real-time market news từ nhiều nguồn lớn như Yahoo, Bloomberg, CNBC, MarketWatch, v.v. — qua Marketaux."
|
| 34 |
+
).launch()
|