seawolf2357 commited on
Commit
e312573
ยท
verified ยท
1 Parent(s): 79694b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
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 " in time_str:
 
59
  return True
60
 
61
- if "hours ago " in time_str:
 
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 {