nick5363 commited on
Commit
957913b
·
verified ·
1 Parent(s): 243a4a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -36
app.py CHANGED
@@ -9,40 +9,6 @@ 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
  # Twitter RSS (X.com) - DeItaone và Unusual_Whales qua Nitter (auto mirror)
47
  try:
48
  def fetch_twitter_rss(username):
@@ -58,7 +24,7 @@ def get_combined_news():
58
  rss_url = f"{mirror}/{username}/rss"
59
  feed = feedparser.parse(rss_url)
60
  if len(feed.entries) > 0:
61
- return feed.entries[:3]
62
  return []
63
 
64
  for user in ["DeItaone", "unusual_whales"]:
@@ -71,4 +37,56 @@ def get_combined_news():
71
 
72
  return result
73
 
74
- gr.Interface(get_combined_news, inputs=[], outputs="markdown", title="Tin Tức Thị Trường Tổng Hợp").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  result = "\n\n"
10
  index = 1
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Twitter RSS (X.com) - DeItaone và Unusual_Whales qua Nitter (auto mirror)
13
  try:
14
  def fetch_twitter_rss(username):
 
24
  rss_url = f"{mirror}/{username}/rss"
25
  feed = feedparser.parse(rss_url)
26
  if len(feed.entries) > 0:
27
+ return feed.entries[:10]
28
  return []
29
 
30
  for user in ["DeItaone", "unusual_whales"]:
 
37
 
38
  return result
39
 
40
+ # VnExpress Kinh Doanh
41
+ try:
42
+ vnexpress_url = "https://vnexpress.net/rss/kinh-doanh.rss"
43
+ vn_feed = feedparser.parse(vnexpress_url)
44
+ for entry in vn_feed.entries[:5]:
45
+ result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
46
+ index += 1
47
+ except:
48
+ result += "*Lỗi khi lấy tin từ VnExpress*\n\n"
49
+
50
+ # Marketaux
51
+ try:
52
+ url = f"https://api.marketaux.com/v1/news/all?language=en&limit=3&api_token={API_KEY}"
53
+ data = requests.get(url).json()
54
+ for article in data.get("data", []):
55
+ title = article.get("title", "No title")
56
+ link = article.get("url", "#")
57
+ source = article.get("source", "Unknown")
58
+ published = article.get("published_at", "")
59
+ result += f"**{index}. [{title}]({link})** \n<sub>{source} – {published}</sub>\n\n"
60
+ index += 1
61
+ except:
62
+ result += "*Lỗi khi lấy từ Marketaux*\n\n"
63
+
64
+ # Google RSS (Yahoo Finance)
65
+ try:
66
+ feed_url = "https://news.google.com/rss/search?q=site:finance.yahoo.com&hl=en-US&gl=US&ceid=US:en"
67
+ feed = feedparser.parse(feed_url)
68
+ for entry in feed.entries[:10]:
69
+ result += f"**{index}. [{entry.title}]({entry.link})** \n<sub>{entry.published}</sub>\n\n"
70
+ index += 1
71
+ except:
72
+ result += "*Lỗi khi lấy từ Google RSS*\n\n"
73
+
74
+
75
+
76
+
77
+
78
+ # Tự động load luôn khi mở web (live=True)
79
+ # Giao diện Gradio với theme tối + tự chạy
80
+ theme = gr.themes.Base().set(
81
+ body_background_fill="#000000", # nền đen
82
+ body_text_color="#ffffff", # chữ trắng
83
+ )
84
+
85
+ gr.Interface(
86
+ fn=get_combined_news,
87
+ inputs=None,
88
+ outputs="markdown",
89
+ live=True, # tự động chạy khi mở web
90
+ theme=theme,
91
+
92
+ ).launch()