MoneyRadar / app.py
seawolf2357's picture
Update app.py
ab30506 verified
raw
history blame
1.44 kB
import gradio as gr
from gnewsclient import gnewsclient
from datetime import datetime, timedelta
# Google ๋‰ด์Šค ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
client = gnewsclient.NewsClient()
# ์ง€์›๋˜๋Š” ๊ตญ๊ฐ€ ๋ชฉ๋ก
supported_countries = client.locations
def get_news(country, keyword):
# ๊ตญ๊ฐ€ ์„ค์ •
client.location = country
client.language = 'en' # ์˜์–ด๋กœ ์„ค์ •
# ํ˜„์žฌ ์‹œ๊ฐ„ ๊ธฐ์ค€ 24์‹œ๊ฐ„ ์ „ ์‹œ๊ฐ„ ๊ณ„์‚ฐ
time_threshold = datetime.now() - timedelta(hours=24)
# ๋‰ด์Šค ๊ฒ€์ƒ‰
news_items = client.get_news(keyword)
# 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค๋งŒ ํ•„ํ„ฐ๋งํ•˜๊ณ  ์ œ๋ชฉ๊ณผ ๋งํฌ ์ถ”์ถœ
filtered_news = []
for item in news_items:
if 'published' in item:
news_date = datetime.strptime(item['published'], "%a, %d %b %Y %H:%M:%S %Z")
if news_date > time_threshold:
filtered_news.append(f"Title: {item['title']}\nLink: {item['link']}\n")
return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
iface = gr.Interface(
fn=get_news,
inputs=[
gr.Dropdown(choices=supported_countries, label="Select Country"),
gr.Textbox(label="Enter keyword")
],
outputs="text",
title="Google News Search",
description="Search for news articles from the last 24 hours using Google News."
)
# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
iface.launch()