Update app.py
Browse files
app.py
CHANGED
@@ -49,32 +49,21 @@ def search_serphouse(query, country, page, num_result):
|
|
49 |
return f"Error: {str(e)}"
|
50 |
|
51 |
def is_recent_news(time_str):
|
52 |
-
debug_info = f"Checking time: {time_str}\n"
|
53 |
if not time_str:
|
54 |
-
|
55 |
-
return False, debug_info
|
56 |
time_parts = time_str.lower().split()
|
57 |
-
debug_info += f"Time parts: {time_parts}\n"
|
58 |
if len(time_parts) < 2:
|
59 |
-
|
60 |
-
return False, debug_info
|
61 |
try:
|
62 |
value = int(time_parts[0])
|
63 |
unit = time_parts[1]
|
64 |
-
debug_info += f"Value: {value}, Unit: {unit}\n"
|
65 |
if unit in ['minute', 'minutes', 'hour', 'hours']:
|
66 |
-
|
67 |
-
return True, debug_info
|
68 |
elif unit in ['day', 'days']:
|
69 |
-
|
70 |
-
debug_info += f"Within days, is recent: {is_recent}\n"
|
71 |
-
return is_recent, debug_info
|
72 |
-
else:
|
73 |
-
debug_info += f"Unknown unit: {unit}\n"
|
74 |
-
return False, debug_info
|
75 |
except ValueError:
|
76 |
-
|
77 |
-
|
78 |
|
79 |
def format_results(results):
|
80 |
all_results = "## All News Results\n\n"
|
@@ -90,8 +79,8 @@ def format_results(results):
|
|
90 |
|
91 |
for result in news_results:
|
92 |
time_str = result.get("time", "Unknown time")
|
93 |
-
is_recent
|
94 |
-
debug_info += f"Article: {result.get('title', 'No Title')}\
|
95 |
|
96 |
all_results += f"""
|
97 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
|
|
49 |
return f"Error: {str(e)}"
|
50 |
|
51 |
def is_recent_news(time_str):
|
|
|
52 |
if not time_str:
|
53 |
+
return False
|
|
|
54 |
time_parts = time_str.lower().split()
|
|
|
55 |
if len(time_parts) < 2:
|
56 |
+
return False
|
|
|
57 |
try:
|
58 |
value = int(time_parts[0])
|
59 |
unit = time_parts[1]
|
|
|
60 |
if unit in ['minute', 'minutes', 'hour', 'hours']:
|
61 |
+
return True
|
|
|
62 |
elif unit in ['day', 'days']:
|
63 |
+
return value <= 1
|
|
|
|
|
|
|
|
|
|
|
64 |
except ValueError:
|
65 |
+
return False
|
66 |
+
return False
|
67 |
|
68 |
def format_results(results):
|
69 |
all_results = "## All News Results\n\n"
|
|
|
79 |
|
80 |
for result in news_results:
|
81 |
time_str = result.get("time", "Unknown time")
|
82 |
+
is_recent = is_recent_news(time_str)
|
83 |
+
debug_info += f"Article: {result.get('title', 'No Title')}\nTime: {time_str}, Is Recent: {is_recent}\n\n"
|
84 |
|
85 |
all_results += f"""
|
86 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|