seawolf2357 commited on
Commit
3adcf52
·
verified ·
1 Parent(s): 73ed8f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
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
- debug_info += "Time string is empty\n"
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
- debug_info += "Time parts less than 2\n"
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
- debug_info += "Within minutes or hours\n"
67
- return True, debug_info
68
  elif unit in ['day', 'days']:
69
- is_recent = value <= 1
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
- debug_info += f"ValueError when parsing: {time_parts[0]}\n"
77
- return False, debug_info
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, time_debug = is_recent_news(time_str)
94
- debug_info += f"Article: {result.get('title', 'No Title')}\n{time_debug}\n"
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', '#')})