seawolf2357 commited on
Commit
23588da
ยท
verified ยท
1 Parent(s): 5713020

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
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
- if time_str == "1 day ago":
57
- return True
 
 
 
 
 
 
58
 
59
- if "hours ago" in time_str:
60
- try:
61
- hours = int(time_str.split()[0])
62
- return hours <= 24
63
- except ValueError:
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์›๋ณธ ์‹œ๊ฐ„ ๋ฌธ์ž์—ด: {time_str}\n\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})