Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -26,13 +26,19 @@ def search_news(keyword, country):
|
|
26 |
|
27 |
def search_news_impl(keyword, country):
|
28 |
url = "https://www.googleapis.com/customsearch/v1"
|
|
|
|
|
|
|
|
|
|
|
29 |
params = {
|
30 |
'key': API_KEY,
|
31 |
'cx': SEARCH_ENGINE_ID,
|
32 |
-
'q': f"{keyword}
|
33 |
'lr': 'lang_en', # 영어 결과만
|
34 |
-
'sort': 'date', # 날짜순 정렬
|
35 |
'num': 100, # 최대 100개 결과
|
|
|
36 |
}
|
37 |
|
38 |
if country != 'All Countries':
|
|
|
26 |
|
27 |
def search_news_impl(keyword, country):
|
28 |
url = "https://www.googleapis.com/customsearch/v1"
|
29 |
+
|
30 |
+
# 날짜 범위 설정 (최근 24시간)
|
31 |
+
end_date = datetime.utcnow()
|
32 |
+
start_date = end_date - timedelta(days=1)
|
33 |
+
|
34 |
params = {
|
35 |
'key': API_KEY,
|
36 |
'cx': SEARCH_ENGINE_ID,
|
37 |
+
'q': f"{keyword} site:news.google.com",
|
38 |
'lr': 'lang_en', # 영어 결과만
|
39 |
+
'sort': 'date:r:20230101:99999999', # 날짜순 정렬
|
40 |
'num': 100, # 최대 100개 결과
|
41 |
+
'dateRestrict': 'd1', # 최근 1일 내 결과만
|
42 |
}
|
43 |
|
44 |
if country != 'All Countries':
|