Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from datetime import datetime, timedelta
|
@@ -12,15 +13,10 @@ COUNTRY_CODES = "ae ar at au be bg br ca ch cn co cu cz de eg fr gb gr hk hu id
|
|
12 |
|
13 |
# 국가 코드와 이름 매핑
|
14 |
COUNTRIES = {'all': 'All Countries'}
|
15 |
-
for code in COUNTRY_CODES
|
16 |
-
try:
|
17 |
-
country = pycountry.countries.get(alpha_2=code.upper())
|
18 |
-
COUNTRIES[code] = country.name
|
19 |
-
except AttributeError:
|
20 |
-
COUNTRIES[code] = code.upper()
|
21 |
|
22 |
def get_news(keyword, article_count, country):
|
23 |
-
country_code =
|
24 |
|
25 |
if country_code == 'all':
|
26 |
base_url = "https://newsapi.org/v2/everything"
|
@@ -36,7 +32,6 @@ def get_news(keyword, article_count, country):
|
|
36 |
params = {
|
37 |
'apiKey': API_KEY,
|
38 |
'q': keyword,
|
39 |
-
'language': 'en',
|
40 |
'country': country_code,
|
41 |
'pageSize': article_count
|
42 |
}
|
@@ -65,7 +60,7 @@ def get_news(keyword, article_count, country):
|
|
65 |
articles = news_data['articles']
|
66 |
|
67 |
if not articles:
|
68 |
-
return (f"<p>No recent news found for the keyword '<strong>{keyword}</strong>' within the last 48 hours.<br>"
|
69 |
f"Try a different keyword or check back later.</p><pre>{debug_info}</pre>")
|
70 |
|
71 |
html_output = f"<h2>News results for '{keyword}' in {country}</h2>"
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
from datetime import datetime, timedelta
|
|
|
13 |
|
14 |
# 국가 코드와 이름 매핑
|
15 |
COUNTRIES = {'all': 'All Countries'}
|
16 |
+
COUNTRIES.update({code: pycountry.countries.get(alpha_2=code.upper()).name for code in COUNTRY_CODES if pycountry.countries.get(alpha_2=code.upper())})
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def get_news(keyword, article_count, country):
|
19 |
+
country_code = next((code for code, name in COUNTRIES.items() if name == country), 'all')
|
20 |
|
21 |
if country_code == 'all':
|
22 |
base_url = "https://newsapi.org/v2/everything"
|
|
|
32 |
params = {
|
33 |
'apiKey': API_KEY,
|
34 |
'q': keyword,
|
|
|
35 |
'country': country_code,
|
36 |
'pageSize': article_count
|
37 |
}
|
|
|
60 |
articles = news_data['articles']
|
61 |
|
62 |
if not articles:
|
63 |
+
return (f"<p>No recent news found for the keyword '<strong>{keyword}</strong>' in {country} within the last 48 hours.<br>"
|
64 |
f"Try a different keyword or check back later.</p><pre>{debug_info}</pre>")
|
65 |
|
66 |
html_output = f"<h2>News results for '{keyword}' in {country}</h2>"
|