Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import json
|
|
8 |
API_KEY = "37d83e266422487b8b2e4cb6e1ff0aa6"
|
9 |
|
10 |
|
11 |
-
|
12 |
COUNTRY_CODES = "ae ar at au be bg br ca ch cn co cu cz de eg fr gb gr hk hu id ie il in it jp kr lt lv ma mx my ng nl no nz ph pl pt ro rs ru sa se sg si sk th tr tw ua us ve za".split()
|
13 |
|
14 |
COUNTRIES = {'all': 'All Countries'}
|
@@ -27,7 +26,7 @@ def get_news(keyword, article_count, country):
|
|
27 |
'q': keyword,
|
28 |
'language': 'en',
|
29 |
'sortBy': 'publishedAt',
|
30 |
-
'pageSize': article_count
|
31 |
}
|
32 |
else:
|
33 |
base_url = "https://newsapi.org/v2/top-headlines"
|
@@ -35,7 +34,7 @@ def get_news(keyword, article_count, country):
|
|
35 |
'apiKey': API_KEY,
|
36 |
'q': keyword,
|
37 |
'country': country_code,
|
38 |
-
'pageSize': article_count
|
39 |
}
|
40 |
|
41 |
two_days_ago = (datetime.utcnow() - timedelta(hours=48)).isoformat()
|
@@ -61,7 +60,10 @@ def get_news(keyword, article_count, country):
|
|
61 |
|
62 |
articles = news_data['articles']
|
63 |
|
64 |
-
|
|
|
|
|
|
|
65 |
if country_code != 'all':
|
66 |
# 특정 국가에서 결과가 없을 경우, 전체 국가에서 검색
|
67 |
return get_news(keyword, article_count, 'All Countries')
|
@@ -82,7 +84,9 @@ def get_news(keyword, article_count, country):
|
|
82 |
else:
|
83 |
html_output += f"<p><em>Showing results specifically for {country}</em></p>"
|
84 |
|
85 |
-
|
|
|
|
|
86 |
title = article['title']
|
87 |
link = article['url']
|
88 |
pub_date = datetime.strptime(article['publishedAt'], "%Y-%m-%dT%H:%M:%SZ")
|
|
|
8 |
API_KEY = "37d83e266422487b8b2e4cb6e1ff0aa6"
|
9 |
|
10 |
|
|
|
11 |
COUNTRY_CODES = "ae ar at au be bg br ca ch cn co cu cz de eg fr gb gr hk hu id ie il in it jp kr lt lv ma mx my ng nl no nz ph pl pt ro rs ru sa se sg si sk th tr tw ua us ve za".split()
|
12 |
|
13 |
COUNTRIES = {'all': 'All Countries'}
|
|
|
26 |
'q': keyword,
|
27 |
'language': 'en',
|
28 |
'sortBy': 'publishedAt',
|
29 |
+
'pageSize': min(article_count * 2, 100) # 요청 기사 수를 2배로 늘림 (최대 100)
|
30 |
}
|
31 |
else:
|
32 |
base_url = "https://newsapi.org/v2/top-headlines"
|
|
|
34 |
'apiKey': API_KEY,
|
35 |
'q': keyword,
|
36 |
'country': country_code,
|
37 |
+
'pageSize': min(article_count * 2, 100) # 요청 기사 수를 2배로 늘림 (최대 100)
|
38 |
}
|
39 |
|
40 |
two_days_ago = (datetime.utcnow() - timedelta(hours=48)).isoformat()
|
|
|
60 |
|
61 |
articles = news_data['articles']
|
62 |
|
63 |
+
# removed 기사 필터링
|
64 |
+
filtered_articles = [article for article in articles if article.get('title') != '[Removed]' and article.get('description') != '[Removed]']
|
65 |
+
|
66 |
+
if not filtered_articles:
|
67 |
if country_code != 'all':
|
68 |
# 특정 국가에서 결과가 없을 경우, 전체 국가에서 검색
|
69 |
return get_news(keyword, article_count, 'All Countries')
|
|
|
84 |
else:
|
85 |
html_output += f"<p><em>Showing results specifically for {country}</em></p>"
|
86 |
|
87 |
+
html_output += f"<p>Found {len(filtered_articles)} relevant articles (after removing any '[Removed]' articles)</p>"
|
88 |
+
|
89 |
+
for article in filtered_articles[:article_count]: # 요청한 기사 수만큼만 표시
|
90 |
title = article['title']
|
91 |
link = article['url']
|
92 |
pub_date = datetime.strptime(article['publishedAt'], "%Y-%m-%dT%H:%M:%SZ")
|