Update app.py
Browse files
app.py
CHANGED
@@ -48,24 +48,17 @@ def search_serphouse(query, country, page, num_result):
|
|
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):
|
@@ -73,9 +66,9 @@ def format_results(results):
|
|
73 |
recent_results = "## 최근 뉴스 결과 (1일 이내)\n\n"
|
74 |
debug_info = "## 디버그 정보\n\n"
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
81 |
|
@@ -97,14 +90,11 @@ def format_results(results):
|
|
97 |
channel = result.get("channel", "알 수 없음")
|
98 |
time_str = result.get("time", "알 수 없는 시간")
|
99 |
|
100 |
-
print(f"\nProcessing news item: {title}")
|
101 |
-
print(f"Time string from API: '{time_str}'")
|
102 |
-
|
103 |
is_recent = is_recent_news(time_str)
|
104 |
debug_info += f"기사: {title}\n시간: {time_str}, 최근 여부: {is_recent}\n\n"
|
105 |
|
106 |
-
#
|
107 |
-
|
108 |
|
109 |
article_info = f"""
|
110 |
### [{title}]({url})
|
@@ -124,14 +114,14 @@ def format_results(results):
|
|
124 |
debug_info += error_message + "\n"
|
125 |
all_results = error_message + "\n\n"
|
126 |
recent_results = error_message + "\n\n"
|
127 |
-
|
128 |
|
129 |
-
return all_results, recent_results,
|
130 |
|
131 |
def serphouse_search(query, country, page, num_result):
|
132 |
results = search_serphouse(query, country, page, num_result)
|
133 |
-
all_results, recent_results,
|
134 |
-
return all_results, recent_results,
|
135 |
|
136 |
css = """
|
137 |
footer {
|
@@ -150,7 +140,7 @@ iface = gr.Interface(
|
|
150 |
outputs=[
|
151 |
gr.Markdown(label="모든 결과"),
|
152 |
gr.Markdown(label="최근 결과 (1일 이내)"),
|
153 |
-
gr.Markdown(label="
|
154 |
],
|
155 |
title="SERPHouse 뉴스 검색 인터페이스",
|
156 |
description="검색어를 입력하고 국가를 선택하여 SERPHouse API에서 뉴스 결과를 가져옵니다. 최근 결과(1일 이내)는 별도로 표시됩니다.",
|
|
|
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 "1 day ago" in time_str:
|
|
|
57 |
return True
|
58 |
|
59 |
if "hours ago" in time_str:
|
|
|
60 |
return True
|
61 |
|
|
|
62 |
return False
|
63 |
|
64 |
def format_results(results):
|
|
|
66 |
recent_results = "## 최근 뉴스 결과 (1일 이내)\n\n"
|
67 |
debug_info = "## 디버그 정보\n\n"
|
68 |
|
69 |
+
result_table = "## 뉴스 결과 표\n\n"
|
70 |
+
result_table += "| 제목 | 링크 | 시간 | 최근 여부 |\n"
|
71 |
+
result_table += "|------|------|------|----------|\n"
|
72 |
|
73 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
74 |
|
|
|
90 |
channel = result.get("channel", "알 수 없음")
|
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\n"
|
95 |
|
96 |
+
# 결과 표에 행 추가
|
97 |
+
result_table += f"| {title[:30]}... | [{url[:30]}...]({url}) | {time_str} | {is_recent} |\n"
|
98 |
|
99 |
article_info = f"""
|
100 |
### [{title}]({url})
|
|
|
114 |
debug_info += error_message + "\n"
|
115 |
all_results = error_message + "\n\n"
|
116 |
recent_results = error_message + "\n\n"
|
117 |
+
result_table += f"| 오류 발생 | - | - | - |\n"
|
118 |
|
119 |
+
return all_results, recent_results, result_table + "\n\n" + debug_info
|
120 |
|
121 |
def serphouse_search(query, country, page, num_result):
|
122 |
results = search_serphouse(query, country, page, num_result)
|
123 |
+
all_results, recent_results, result_table_and_debug = format_results(results)
|
124 |
+
return all_results, recent_results, result_table_and_debug
|
125 |
|
126 |
css = """
|
127 |
footer {
|
|
|
140 |
outputs=[
|
141 |
gr.Markdown(label="모든 결과"),
|
142 |
gr.Markdown(label="최근 결과 (1일 이내)"),
|
143 |
+
gr.Markdown(label="결과 표 및 디버그 정보")
|
144 |
],
|
145 |
title="SERPHouse 뉴스 검색 인터페이스",
|
146 |
description="검색어를 입력하고 국가를 선택하여 SERPHouse API에서 뉴스 결과를 가져옵니다. 최근 결과(1일 이내)는 별도로 표시됩니다.",
|