seawolf2357 commited on
Commit
a31c3ed
1 Parent(s): ba53ac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -48,7 +48,7 @@ def search_serphouse(query, country, verbatim, page, num_result):
48
  except requests.RequestException as e:
49
  return f"Error: {str(e)}"
50
 
51
- def is_within_24_hours(time_str):
52
  time_parts = time_str.split()
53
  if len(time_parts) >= 2:
54
  try:
@@ -56,7 +56,7 @@ def is_within_24_hours(time_str):
56
  unit = time_parts[1].lower()
57
  if unit in ['minute', 'minutes', 'hour', 'hours']:
58
  return True
59
- elif unit == 'day' and value == 1:
60
  return True
61
  except ValueError:
62
  pass
@@ -75,19 +75,16 @@ def format_results(results):
75
  .debug-info { background-color: #f0f0f0; padding: 10px; margin-top: 20px; border-radius: 5px; white-space: pre-wrap; }
76
  </style>
77
  <div class="news-container">
78
- <h2 style="text-align: center; color: #333;">Search Results (Last 24 Hours)</h2>
79
  """
80
 
81
- # 디버깅 정보 추가
82
- html_output += f'<div class="debug-info"><h3>Debug Info:</h3><pre>{json.dumps(results, indent=2)}</pre></div>'
83
-
84
  try:
85
  if isinstance(results, dict) and "results" in results:
86
  news_results = results["results"].get("news", [])
87
- filtered_results = [result for result in news_results if is_within_24_hours(result.get("time", "").strip())]
88
 
89
  if not filtered_results:
90
- html_output += '<p class="no-results">No news results found within the last 24 hours.</p>'
91
  else:
92
  for result in filtered_results:
93
  html_output += f"""
@@ -102,6 +99,9 @@ def format_results(results):
102
  except Exception as e:
103
  html_output += f'<p class="no-results">Error processing results: {str(e)}</p>'
104
 
 
 
 
105
  html_output += "</div>"
106
  return html_output
107
 
@@ -128,7 +128,7 @@ iface = gr.Interface(
128
  ],
129
  outputs="html",
130
  title="SERPHouse News Search Interface",
131
- description="Enter your search query and select a country to get news results from the SERPHouse API. Only articles from the last 24 hours will be displayed.",
132
  theme="Nymbo/Nymbo_Theme",
133
  css=css
134
  )
 
48
  except requests.RequestException as e:
49
  return f"Error: {str(e)}"
50
 
51
+ def is_recent_news(time_str):
52
  time_parts = time_str.split()
53
  if len(time_parts) >= 2:
54
  try:
 
56
  unit = time_parts[1].lower()
57
  if unit in ['minute', 'minutes', 'hour', 'hours']:
58
  return True
59
+ elif unit in ['day', 'days'] and value <= 2: # 최대 2일까지 허용
60
  return True
61
  except ValueError:
62
  pass
 
75
  .debug-info { background-color: #f0f0f0; padding: 10px; margin-top: 20px; border-radius: 5px; white-space: pre-wrap; }
76
  </style>
77
  <div class="news-container">
78
+ <h2 style="text-align: center; color: #333;">Recent News Results</h2>
79
  """
80
 
 
 
 
81
  try:
82
  if isinstance(results, dict) and "results" in results:
83
  news_results = results["results"].get("news", [])
84
+ filtered_results = [result for result in news_results if is_recent_news(result.get("time", "").strip())]
85
 
86
  if not filtered_results:
87
+ html_output += '<p class="no-results">No recent news results found.</p>'
88
  else:
89
  for result in filtered_results:
90
  html_output += f"""
 
99
  except Exception as e:
100
  html_output += f'<p class="no-results">Error processing results: {str(e)}</p>'
101
 
102
+ # 디버그 정보 추가 (실제 사용 시 제거 가능)
103
+ html_output += f'<div class="debug-info"><h3>Debug Info:</h3><pre>{json.dumps(results, indent=2)}</pre></div>'
104
+
105
  html_output += "</div>"
106
  return html_output
107
 
 
128
  ],
129
  outputs="html",
130
  title="SERPHouse News Search Interface",
131
+ description="Enter your search query and select a country to get recent news results from the SERPHouse API.",
132
  theme="Nymbo/Nymbo_Theme",
133
  css=css
134
  )