Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
|
|
5 |
|
6 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
7 |
|
@@ -47,22 +48,29 @@ def search_serphouse(query, country, page, num_result):
|
|
47 |
except requests.RequestException as e:
|
48 |
return f"Error: {str(e)}"
|
49 |
|
|
|
50 |
def is_recent_news(time_str):
|
51 |
if not time_str:
|
52 |
return False
|
53 |
|
54 |
time_str = time_str.lower().strip()
|
55 |
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
if "hours ago" in time_str:
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
return False
|
65 |
|
|
|
66 |
return False
|
67 |
|
68 |
def format_results(results):
|
@@ -91,7 +99,7 @@ def format_results(results):
|
|
91 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
92 |
|
93 |
is_recent = is_recent_news(time_str)
|
94 |
-
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n
|
95 |
|
96 |
article_info = f"""
|
97 |
### [{title}]({url})
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
from datetime import datetime, timedelta
|
5 |
+
import re
|
6 |
|
7 |
API_KEY = "V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6"
|
8 |
|
|
|
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 |
+
# ๋๋ฒ๊ทธ ์ถ๋ ฅ
|
59 |
+
print(f"Processing time string: {time_str}")
|
60 |
+
|
61 |
+
if "day ago" in time_str or "days ago" in time_str:
|
62 |
+
days = int(re.findall(r'\d+', time_str)[0])
|
63 |
+
result = days <= 1
|
64 |
+
print(f"Days ago: {days}, Result: {result}")
|
65 |
+
return result
|
66 |
|
67 |
+
if "hour ago" in time_str or "hours ago" in time_str:
|
68 |
+
hours = int(re.findall(r'\d+', time_str)[0])
|
69 |
+
result = hours <= 24
|
70 |
+
print(f"Hours ago: {hours}, Result: {result}")
|
71 |
+
return result
|
|
|
72 |
|
73 |
+
print(f"No match found for: {time_str}")
|
74 |
return False
|
75 |
|
76 |
def format_results(results):
|
|
|
99 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
100 |
|
101 |
is_recent = is_recent_news(time_str)
|
102 |
+
debug_info += f"๊ธฐ์ฌ: {title}\n์๊ฐ: {time_str}, ์ต๊ทผ ์ฌ๋ถ: {is_recent}\n\n"
|
103 |
|
104 |
article_info = f"""
|
105 |
### [{title}]({url})
|