Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
from datetime import datetime, timedelta
|
4 |
|
5 |
-
# Google
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
def get_news(country, keyword):
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# ํ์ฌ ์๊ฐ ๊ธฐ์ค 24์๊ฐ ์ ์๊ฐ ๊ณ์ฐ
|
17 |
time_threshold = datetime.now() - timedelta(hours=24)
|
18 |
|
19 |
-
#
|
20 |
-
news_items = client.get_news()
|
21 |
-
|
22 |
-
# 24์๊ฐ ์ด๋ด์ ๋ด์ค๋ง ํํฐ๋งํ๊ณ ์ ๋ชฉ๊ณผ ๋งํฌ ์ถ์ถ
|
23 |
filtered_news = []
|
24 |
-
for
|
25 |
-
if
|
26 |
-
|
27 |
-
if
|
28 |
-
filtered_news.append(f"Title: {
|
29 |
|
30 |
return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
|
31 |
|
@@ -33,12 +39,12 @@ def get_news(country, keyword):
|
|
33 |
iface = gr.Interface(
|
34 |
fn=get_news,
|
35 |
inputs=[
|
36 |
-
gr.Dropdown(choices=
|
37 |
gr.Textbox(label="Enter keyword")
|
38 |
],
|
39 |
outputs="text",
|
40 |
title="Google News Search",
|
41 |
-
description="Search for news articles from the last 24 hours using Google News."
|
42 |
)
|
43 |
|
44 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import feedparser
|
4 |
from datetime import datetime, timedelta
|
5 |
|
6 |
+
# ์ง์๋๋ ๊ตญ๊ฐ ๋ฐ ํด๋น Google News URL
|
7 |
+
SUPPORTED_COUNTRIES = {
|
8 |
+
'United States': 'https://news.google.com/rss?hl=en-US&gl=US&ceid=US:en',
|
9 |
+
'United Kingdom': 'https://news.google.com/rss?hl=en-GB&gl=GB&ceid=GB:en',
|
10 |
+
'Australia': 'https://news.google.com/rss?hl=en-AU&gl=AU&ceid=AU:en',
|
11 |
+
'India': 'https://news.google.com/rss?hl=en-IN&gl=IN&ceid=IN:en',
|
12 |
+
'Canada': 'https://news.google.com/rss?hl=en-CA&gl=CA&ceid=CA:en'
|
13 |
+
}
|
14 |
|
15 |
def get_news(country, keyword):
|
16 |
+
if country not in SUPPORTED_COUNTRIES:
|
17 |
+
return "Selected country is not supported."
|
18 |
+
|
19 |
+
url = SUPPORTED_COUNTRIES[country]
|
20 |
+
|
21 |
+
# RSS ํผ๋ ๊ฐ์ ธ์ค๊ธฐ
|
22 |
+
response = requests.get(url)
|
23 |
+
feed = feedparser.parse(response.content)
|
24 |
|
25 |
# ํ์ฌ ์๊ฐ ๊ธฐ์ค 24์๊ฐ ์ ์๊ฐ ๊ณ์ฐ
|
26 |
time_threshold = datetime.now() - timedelta(hours=24)
|
27 |
|
28 |
+
# ํค์๋์ ์ผ์นํ๊ณ 24์๊ฐ ์ด๋ด์ ๋ด์ค๋ง ํํฐ๋ง
|
|
|
|
|
|
|
29 |
filtered_news = []
|
30 |
+
for entry in feed.entries:
|
31 |
+
if keyword.lower() in entry.title.lower():
|
32 |
+
pub_date = datetime(*entry.published_parsed[:6])
|
33 |
+
if pub_date > time_threshold:
|
34 |
+
filtered_news.append(f"Title: {entry.title}\nLink: {entry.link}\n")
|
35 |
|
36 |
return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
|
37 |
|
|
|
39 |
iface = gr.Interface(
|
40 |
fn=get_news,
|
41 |
inputs=[
|
42 |
+
gr.Dropdown(choices=list(SUPPORTED_COUNTRIES.keys()), label="Select Country"),
|
43 |
gr.Textbox(label="Enter keyword")
|
44 |
],
|
45 |
outputs="text",
|
46 |
title="Google News Search",
|
47 |
+
description="Search for news articles from the last 24 hours using Google News RSS feeds."
|
48 |
)
|
49 |
|
50 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|