File size: 2,035 Bytes
4879aed
 
 
 
 
 
 
 
 
 
 
bd3d5fc
 
 
 
 
 
 
 
 
 
4879aed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd3d5fc
4879aed
 
 
08a6a9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65

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()