Update app.py
Browse files
app.py
CHANGED
@@ -80,6 +80,12 @@ def create_deepseek_interface():
|
|
80 |
lang = "ko" if is_korean else "en"
|
81 |
loc = "kr" if is_korean else "us"
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# SerpHouse API ํธ์ถ ์คํ - POST ๋ฉ์๋ ์ฌ์ฉ (MoneyRadar ์ฝ๋ ์ฐธ๊ณ )
|
84 |
url = "https://api.serphouse.com/serp/live"
|
85 |
|
@@ -91,9 +97,11 @@ def create_deepseek_interface():
|
|
91 |
"loc": loc,
|
92 |
"lang": lang,
|
93 |
"device": "desktop",
|
94 |
-
"serp_type": "
|
95 |
"page": "1",
|
96 |
-
"num": "5"
|
|
|
|
|
97 |
}
|
98 |
}
|
99 |
|
@@ -106,45 +114,60 @@ def create_deepseek_interface():
|
|
106 |
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {search_query}")
|
107 |
print(f"์์ฒญ ๋ฐฉ์: POST, ํ์ด๋ก๋: {payload}")
|
108 |
|
109 |
-
# POST ์์ฒญ ์ํ
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
response.raise_for_status()
|
112 |
|
113 |
print(f"SerpHouse API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
114 |
search_results = response.json()
|
115 |
|
116 |
-
#
|
117 |
print(f"์๋ต ๊ตฌ์กฐ: {list(search_results.keys()) if isinstance(search_results, dict) else '๋์
๋๋ฆฌ ์๋'}")
|
118 |
|
119 |
-
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
120 |
formatted_results = []
|
121 |
formatted_results.append(f"๊ฒ์์ด: {search_query}\n\n")
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
title = result.get("title", "์ ๋ชฉ ์์")
|
129 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
-
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(
|
134 |
return "".join(formatted_results)
|
135 |
|
136 |
-
# ๋ค๋ฅธ ๊ฐ๋ฅํ ๊ฒฐ๊ณผ ๊ตฌ์กฐ ํ์ธ
|
137 |
-
if isinstance(search_results, dict) and "organic" in search_results:
|
138 |
-
organic_results = search_results["organic"]
|
139 |
-
for result in organic_results[:5]:
|
140 |
-
title = result.get("title", "์ ๋ชฉ ์์")
|
141 |
-
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
142 |
-
link = result.get("link", "#")
|
143 |
-
formatted_results.append(f"์ ๋ชฉ: {title}\n๋ด์ฉ: {snippet}\n๋งํฌ: {link}\n\n")
|
144 |
-
|
145 |
-
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(organic_results)}๊ฐ ์ฐพ์")
|
146 |
-
return "".join(formatted_results)
|
147 |
-
|
148 |
print("๊ฒ์ ๊ฒฐ๊ณผ ์์ ๋๋ ์๋ต ํ์ ๋ถ์ผ์น")
|
149 |
print(f"์๋ต ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {str(search_results)[:300]}...")
|
150 |
return f"๊ฒ์์ด '{search_query}'์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์๊ฑฐ๋ API ์๋ต ํ์์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|
|
|
80 |
lang = "ko" if is_korean else "en"
|
81 |
loc = "kr" if is_korean else "us"
|
82 |
|
83 |
+
# MoneyRadar ๋ฐฉ์ ์ ํํ ๋ฐ๋ฅด๊ธฐ - serp_type์ news๋ก ๋ณ๊ฒฝํ๊ณ ๋ ์ง ๋ฒ์ ์ถ๊ฐ
|
84 |
+
from datetime import datetime, timedelta
|
85 |
+
now = datetime.utcnow()
|
86 |
+
yesterday = now - timedelta(days=1)
|
87 |
+
date_range = f"{yesterday.strftime('%Y-%m-%d')},{now.strftime('%Y-%m-%d')}"
|
88 |
+
|
89 |
# SerpHouse API ํธ์ถ ์คํ - POST ๋ฉ์๋ ์ฌ์ฉ (MoneyRadar ์ฝ๋ ์ฐธ๊ณ )
|
90 |
url = "https://api.serphouse.com/serp/live"
|
91 |
|
|
|
97 |
"loc": loc,
|
98 |
"lang": lang,
|
99 |
"device": "desktop",
|
100 |
+
"serp_type": "news", # web์์ news๋ก ๋ณ๊ฒฝ
|
101 |
"page": "1",
|
102 |
+
"num": "5",
|
103 |
+
"date_range": date_range, # ๋ ์ง ๋ฒ์ ์ถ๊ฐ
|
104 |
+
"sort_by": "date" # ๋ ์ง์ ์ ๋ ฌ ์ถ๊ฐ
|
105 |
}
|
106 |
}
|
107 |
|
|
|
114 |
print(f"SerpHouse API ํธ์ถ ์ค... ๊ฒ์์ด: {search_query}")
|
115 |
print(f"์์ฒญ ๋ฐฉ์: POST, ํ์ด๋ก๋: {payload}")
|
116 |
|
117 |
+
# POST ์์ฒญ ์ํ (์ธ์
๊ณผ ์ฌ์๋ ๋ก์ง ์ถ๊ฐ)
|
118 |
+
session = requests.Session()
|
119 |
+
retries = requests.packages.urllib3.util.retry.Retry(
|
120 |
+
total=5,
|
121 |
+
backoff_factor=1,
|
122 |
+
status_forcelist=[500, 502, 503, 504, 429],
|
123 |
+
allowed_methods=["POST"]
|
124 |
+
)
|
125 |
+
adapter = requests.adapters.HTTPAdapter(max_retries=retries)
|
126 |
+
session.mount('http://', adapter)
|
127 |
+
session.mount('https://', adapter)
|
128 |
+
|
129 |
+
response = session.post(
|
130 |
+
url,
|
131 |
+
json=payload,
|
132 |
+
headers=headers,
|
133 |
+
timeout=(30, 30)
|
134 |
+
)
|
135 |
+
|
136 |
response.raise_for_status()
|
137 |
|
138 |
print(f"SerpHouse API ์๋ต ์ํ ์ฝ๋: {response.status_code}")
|
139 |
search_results = response.json()
|
140 |
|
141 |
+
# MoneyRadar์ ๊ฒฐ๊ณผ ์ฒ๋ฆฌ ๋ฐฉ์ ๋ถ์ ๋ฐ ์ ์ฉ
|
142 |
print(f"์๋ต ๊ตฌ์กฐ: {list(search_results.keys()) if isinstance(search_results, dict) else '๋์
๋๋ฆฌ ์๋'}")
|
143 |
|
144 |
+
# ๊ฒ์ ๊ฒฐ๊ณผ ํ์ฑ ๋ฐ ํฌ๋งทํ
|
145 |
formatted_results = []
|
146 |
formatted_results.append(f"๊ฒ์์ด: {search_query}\n\n")
|
147 |
|
148 |
+
# ๊ฒฐ๊ณผ ๊ตฌ์กฐ ํ์ฑ (MoneyRadar์ ๋์ผํ๊ฒ)
|
149 |
+
if "results" in search_results and "results" in search_results["results"]:
|
150 |
+
# ๋ด์ค ๊ฒฐ๊ณผ ํ์ฑ
|
151 |
+
news_results = search_results["results"]["results"].get("news", [])
|
152 |
+
if news_results:
|
153 |
+
for result in news_results[:5]:
|
154 |
title = result.get("title", "์ ๋ชฉ ์์")
|
155 |
snippet = result.get("snippet", "๋ด์ฉ ์์")
|
156 |
+
url = result.get("url", result.get("link", "#"))
|
157 |
+
source = result.get("source", result.get("channel", "์ ์ ์์"))
|
158 |
+
time = result.get("time", result.get("date", "์๊ฐ ์ ๋ณด ์์"))
|
159 |
+
|
160 |
+
formatted_results.append(
|
161 |
+
f"์ ๋ชฉ: {title}\n"
|
162 |
+
f"์ถ์ฒ: {source}\n"
|
163 |
+
f"์๊ฐ: {time}\n"
|
164 |
+
f"๋ด์ฉ: {snippet}\n"
|
165 |
+
f"๋งํฌ: {url}\n\n"
|
166 |
+
)
|
167 |
|
168 |
+
print(f"๊ฒ์ ๊ฒฐ๊ณผ {len(news_results)}๊ฐ ์ฐพ์")
|
169 |
return "".join(formatted_results)
|
170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
print("๊ฒ์ ๊ฒฐ๊ณผ ์์ ๋๋ ์๋ต ํ์ ๋ถ์ผ์น")
|
172 |
print(f"์๋ต ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {str(search_results)[:300]}...")
|
173 |
return f"๊ฒ์์ด '{search_query}'์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์๊ฑฐ๋ API ์๋ต ํ์์ด ์์๊ณผ ๋ค๋ฆ
๋๋ค."
|