Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
-
from bs4 import BeautifulSoup
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
|
| 9 |
-
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
response.raise_for_status()
|
| 14 |
-
soup = BeautifulSoup(response.text, "html.parser")
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
return "Không tìm thấy tin tức nào từ Yahoo Finance. Có thể trang web đã thay đổi cấu trúc."
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
title = article.get_text(strip=True)
|
| 24 |
-
link = article.get("href")
|
| 25 |
-
if link:
|
| 26 |
-
link = link if link.startswith("http") else f"https://finance.yahoo.com{link}"
|
| 27 |
-
result += f"**{i+1}. [{title}]({link})**\n\n"
|
| 28 |
-
else:
|
| 29 |
-
result += f"**{i+1}. {title}** (Không có link)\n\n"
|
| 30 |
-
|
| 31 |
-
return result
|
| 32 |
-
|
| 33 |
-
except requests.exceptions.RequestException as e:
|
| 34 |
-
return f"Lỗi khi tải tin tức: {e}"
|
| 35 |
-
except Exception as e:
|
| 36 |
-
return f"Lỗi không xác định: {e}"
|
| 37 |
-
|
| 38 |
-
# Sửa lỗi cú pháp: thêm dấu = cho title
|
| 39 |
-
interface = gr.Interface(
|
| 40 |
-
fn=get_latest_yahoo_news,
|
| 41 |
inputs=None,
|
| 42 |
outputs="markdown",
|
| 43 |
-
title="Tin
|
| 44 |
-
description="
|
| 45 |
-
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
if __name__ == "__main__":
|
| 49 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
+
import feedparser
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
def get_latest_rss_news():
|
| 5 |
+
feed_url = "https://finance.yahoo.com/news/rssindex"
|
| 6 |
+
feed = feedparser.parse(feed_url)
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
if not feed.entries:
|
| 9 |
+
return "Không tìm thấy tin tức nào từ Yahoo RSS."
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
result = "# Tin tức Mới nhất từ Yahoo Finance (RSS)\n\n"
|
| 12 |
+
for i, entry in enumerate(feed.entries[:5]):
|
| 13 |
+
title = entry.title
|
| 14 |
+
link = entry.link
|
| 15 |
+
published = entry.published
|
| 16 |
+
result += f"**{i+1}. [{title}]({link})** \n<sub>{published}</sub>\n\n"
|
| 17 |
|
| 18 |
+
return result
|
|
|
|
| 19 |
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=get_latest_rss_news,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
inputs=None,
|
| 23 |
outputs="markdown",
|
| 24 |
+
title="Tin tức Mới nhất từ Yahoo (RSS)",
|
| 25 |
+
description="Tự động hiển thị 5 tin tài chính/kỹ thuật/macro mới nhất từ Yahoo Finance – không cần nhập gì."
|
| 26 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|