Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -49,33 +49,37 @@ def search_serphouse(query, country, page, num_result):
|
|
49 |
def format_results(results):
|
50 |
all_results = "## ๋ชจ๋ ๋ด์ค ๊ฒฐ๊ณผ\n\n"
|
51 |
result_table = "## ๋ด์ค ๊ฒฐ๊ณผ ํ\n\n"
|
52 |
-
result_table += "| ์ ๋ชฉ | ๋งํฌ | ์๊ฐ | ์ถ์ฒ |\n"
|
53 |
-
result_table += "
|
54 |
|
55 |
debug_info = "## ๋๋ฒ๊ทธ ์ ๋ณด\n\n"
|
56 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
57 |
|
58 |
try:
|
59 |
if not isinstance(results, dict):
|
60 |
-
raise ValueError("
|
61 |
|
62 |
if "results" not in results:
|
63 |
-
raise ValueError("
|
64 |
|
|
|
65 |
news_results = results["results"].get("news", [])
|
66 |
-
|
67 |
debug_info += f"๋ด์ค ๊ฒฐ๊ณผ ์: {len(news_results)}\n\n"
|
68 |
|
69 |
-
for result in news_results:
|
70 |
title = result.get("title", "์ ๋ชฉ ์์")
|
71 |
url = result.get("url", "#")
|
72 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
73 |
channel = result.get("channel", "์ ์ ์์")
|
74 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
75 |
|
76 |
-
#
|
77 |
-
|
|
|
|
|
|
|
78 |
|
|
|
79 |
article_info = f"""
|
80 |
### [{title}]({url})
|
81 |
{snippet}
|
@@ -89,12 +93,8 @@ def format_results(results):
|
|
89 |
debug_info += error_message + "\n"
|
90 |
all_results = error_message + "\n\n"
|
91 |
|
92 |
-
# ๋๋ฒ๊ทธ
|
93 |
-
result_table += f"| ์ค๋ฅ ๋ฐ์ | - | - | - |\n"
|
94 |
-
result_table += f"| Debug Info | {error_message} | - | - |\n"
|
95 |
-
|
96 |
-
# ๋๋ฒ๊ทธ ์ ๋ณด๋ฅผ ํ์ ์ถ๊ฐ
|
97 |
-
result_table += "| Debug Info | ํฌํจ๋จ | ํฌํจ๋จ | ํฌํจ๋จ |\n"
|
98 |
|
99 |
return all_results, result_table + "\n\n" + debug_info
|
100 |
|
|
|
49 |
def format_results(results):
|
50 |
all_results = "## ๋ชจ๋ ๋ด์ค ๊ฒฐ๊ณผ\n\n"
|
51 |
result_table = "## ๋ด์ค ๊ฒฐ๊ณผ ํ\n\n"
|
52 |
+
result_table += "| ์ ๋ชฉ | ๋งํฌ | ์๊ฐ | ์ถ์ฒ | ๋๋ฒ๊ทธ ์ ๋ณด |\n"
|
53 |
+
result_table += "|------|------|------|------|-------------|\n"
|
54 |
|
55 |
debug_info = "## ๋๋ฒ๊ทธ ์ ๋ณด\n\n"
|
56 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
57 |
|
58 |
try:
|
59 |
if not isinstance(results, dict):
|
60 |
+
raise ValueError("๊ฒฐ๊ณผ๊ฐ ์ฌ์ ํ์์ด ์๋๋๋ค.")
|
61 |
|
62 |
if "results" not in results:
|
63 |
+
raise ValueError("'results' ํค๊ฐ ์๋ต์ ์์ต๋๋ค.")
|
64 |
|
65 |
+
# 'news' ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ด
|
66 |
news_results = results["results"].get("news", [])
|
|
|
67 |
debug_info += f"๋ด์ค ๊ฒฐ๊ณผ ์: {len(news_results)}\n\n"
|
68 |
|
69 |
+
for idx, result in enumerate(news_results):
|
70 |
title = result.get("title", "์ ๋ชฉ ์์")
|
71 |
url = result.get("url", "#")
|
72 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
73 |
channel = result.get("channel", "์ ์ ์์")
|
74 |
time_str = result.get("time", "์ ์ ์๋ ์๊ฐ")
|
75 |
|
76 |
+
# ๊ฐ ๊ฒฐ๊ณผ์ ๋ํ ๋๋ฒ๊ทธ ์ ๋ณด๋ฅผ ๋ฌธ์์ด๋ก ๊ตฌ์ฑ
|
77 |
+
single_debug_info = f"๋ด์ค {idx + 1} - ์ ๋ชฉ: {title}, ๋งํฌ: {url}, ์๊ฐ: {time_str}, ์ถ์ฒ: {channel}"
|
78 |
+
|
79 |
+
# ๊ฒฐ๊ณผ ํ์ ํ ์ถ๊ฐ (๋๋ฒ๊ทธ ์ ๋ณด ํฌํจ)
|
80 |
+
result_table += f"| {title[:30]}... | [{url[:30]}...]({url}) | {time_str} | {channel} | {single_debug_info[:50]}... |\n"
|
81 |
|
82 |
+
# ๋ด์ค ๊ธฐ์ฌ ์ ๋ณด
|
83 |
article_info = f"""
|
84 |
### [{title}]({url})
|
85 |
{snippet}
|
|
|
93 |
debug_info += error_message + "\n"
|
94 |
all_results = error_message + "\n\n"
|
95 |
|
96 |
+
# ์ค๋ฅ ์ ๋๋ฒ๊ทธ ์ ๋ณด๋ ํ์ ์ถ๊ฐ
|
97 |
+
result_table += f"| ์ค๋ฅ ๋ฐ์ | - | - | - | {error_message} |\n"
|
|
|
|
|
|
|
|
|
98 |
|
99 |
return all_results, result_table + "\n\n" + debug_info
|
100 |
|