Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
5 |
-
import re
|
6 |
|
7 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
8 |
|
@@ -48,19 +47,25 @@ def search_serphouse(query, country, page, num_result):
|
|
48 |
except requests.RequestException as e:
|
49 |
return f"Error: {str(e)}"
|
50 |
|
51 |
-
|
52 |
def is_recent_news(time_str):
|
|
|
|
|
53 |
if not time_str:
|
|
|
54 |
return False
|
55 |
|
56 |
time_str = time_str.lower().strip()
|
|
|
57 |
|
58 |
-
if "1 day ago
|
|
|
59 |
return True
|
60 |
|
61 |
-
if "hours ago
|
|
|
62 |
return True
|
63 |
|
|
|
64 |
return False
|
65 |
|
66 |
def format_results(results):
|
@@ -88,6 +93,9 @@ def format_results(results):
|
|
88 |
channel = result.get("channel", "์ ์ ์์")
|
89 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
90 |
|
|
|
|
|
|
|
91 |
is_recent = is_recent_news(time_str)
|
92 |
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n\n"
|
93 |
|
@@ -115,7 +123,7 @@ def format_results(results):
|
|
115 |
def serphouse_search(query, country, page, num_result):
|
116 |
results = search_serphouse(query, country, page, num_result)
|
117 |
all_results, recent_results, debug_info = format_results(results)
|
118 |
-
return all_results, recent_results, debug_info
|
119 |
|
120 |
css = """
|
121 |
footer {
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
|
|
5 |
|
6 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
7 |
|
|
|
47 |
except requests.RequestException as e:
|
48 |
return f"Error: {str(e)}"
|
49 |
|
|
|
50 |
def is_recent_news(time_str):
|
51 |
+
print(f"Received time string: '{time_str}'") # ์
๋ ฅ ๋ฌธ์์ด ์ถ๋ ฅ
|
52 |
+
|
53 |
if not time_str:
|
54 |
+
print("Empty time string, returning False")
|
55 |
return False
|
56 |
|
57 |
time_str = time_str.lower().strip()
|
58 |
+
print(f"Processed time string: '{time_str}'") # ์ฒ๋ฆฌ๋ ๋ฌธ์์ด ์ถ๋ ฅ
|
59 |
|
60 |
+
if "1 day ago" in time_str:
|
61 |
+
print("Matched '1 day ago', returning True")
|
62 |
return True
|
63 |
|
64 |
+
if "hours ago" in time_str:
|
65 |
+
print("Matched 'hours ago', returning True")
|
66 |
return True
|
67 |
|
68 |
+
print(f"No match found for '{time_str}', returning False")
|
69 |
return False
|
70 |
|
71 |
def format_results(results):
|
|
|
93 |
channel = result.get("channel", "์ ์ ์์")
|
94 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
95 |
|
96 |
+
print(f"\nProcessing news item: {title}") # ๊ฐ ๋ด์ค ํญ๋ชฉ ์ฒ๋ฆฌ ์์ ์๋ฆผ
|
97 |
+
print(f"Time string from API: '{time_str}'") # API์์ ๋ฐ์ ์๋ ์๊ฐ ๋ฌธ์์ด
|
98 |
+
|
99 |
is_recent = is_recent_news(time_str)
|
100 |
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n\n"
|
101 |
|
|
|
123 |
def serphouse_search(query, country, page, num_result):
|
124 |
results = search_serphouse(query, country, page, num_result)
|
125 |
all_results, recent_results, debug_info = format_results(results)
|
126 |
+
return all_results, recent_results, debug_info
|
127 |
|
128 |
css = """
|
129 |
footer {
|