Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,6 @@ def get_news(keyword, article_count, country):
|
|
31 |
base_url = "https://newsapi.org/v2/top-headlines"
|
32 |
params = {
|
33 |
'apiKey': API_KEY,
|
34 |
-
'q': keyword,
|
35 |
'country': country_code,
|
36 |
'pageSize': article_count
|
37 |
}
|
@@ -51,20 +50,24 @@ def get_news(keyword, article_count, country):
|
|
51 |
debug_info += f"API Response Headers: {json.dumps(dict(response.headers), indent=2)}\n\n"
|
52 |
debug_info += f"API Response Body: {json.dumps(news_data, indent=2)}\n\n"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
except requests.RequestException as e:
|
55 |
return f"<p style='color: red;'>Error fetching news: {str(e)}</p><pre>{debug_info}</pre>"
|
56 |
|
57 |
if news_data['status'] != 'ok':
|
58 |
return f"<p style='color: red;'>API Error: {news_data.get('message', 'Unknown error occurred')}</p><pre>{debug_info}</pre>"
|
59 |
-
|
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>"
|
67 |
-
for article in articles:
|
68 |
title = article['title']
|
69 |
link = article['url']
|
70 |
pub_date = datetime.strptime(article['publishedAt'], "%Y-%m-%dT%H:%M:%SZ")
|
|
|
31 |
base_url = "https://newsapi.org/v2/top-headlines"
|
32 |
params = {
|
33 |
'apiKey': API_KEY,
|
|
|
34 |
'country': country_code,
|
35 |
'pageSize': article_count
|
36 |
}
|
|
|
50 |
debug_info += f"API Response Headers: {json.dumps(dict(response.headers), indent=2)}\n\n"
|
51 |
debug_info += f"API Response Body: {json.dumps(news_data, indent=2)}\n\n"
|
52 |
|
53 |
+
articles = news_data['articles']
|
54 |
+
|
55 |
+
# 키워드로 기사 필터링
|
56 |
+
if country_code != 'all':
|
57 |
+
articles = [article for article in articles if keyword.lower() in article['title'].lower() or keyword.lower() in article.get('description', '').lower()]
|
58 |
+
|
59 |
except requests.RequestException as e:
|
60 |
return f"<p style='color: red;'>Error fetching news: {str(e)}</p><pre>{debug_info}</pre>"
|
61 |
|
62 |
if news_data['status'] != 'ok':
|
63 |
return f"<p style='color: red;'>API Error: {news_data.get('message', 'Unknown error occurred')}</p><pre>{debug_info}</pre>"
|
|
|
|
|
64 |
|
65 |
if not articles:
|
66 |
return (f"<p>No recent news found for the keyword '<strong>{keyword}</strong>' in {country} within the last 48 hours.<br>"
|
67 |
f"Try a different keyword or check back later.</p><pre>{debug_info}</pre>")
|
68 |
|
69 |
html_output = f"<h2>News results for '{keyword}' in {country}</h2>"
|
70 |
+
for article in articles[:article_count]:
|
71 |
title = article['title']
|
72 |
link = article['url']
|
73 |
pub_date = datetime.strptime(article['publishedAt'], "%Y-%m-%dT%H:%M:%SZ")
|