Update app.py
Browse files
app.py
CHANGED
@@ -184,7 +184,6 @@ MAJOR_COUNTRIES = list(COUNTRY_CODES.keys()) # COUNTRY_LOCATIONS ๋์ COUNTRY
|
|
184 |
def search_serphouse(query, country, page=1, num_result=10):
|
185 |
url = "https://api.serphouse.com/serp/live"
|
186 |
|
187 |
-
# ๊ฒ์์ด ๋ฒ์ญ
|
188 |
translated_query = translate_query(query, country)
|
189 |
print(f"Original query: {query}")
|
190 |
print(f"Translated query: {translated_query}")
|
@@ -193,14 +192,14 @@ def search_serphouse(query, country, page=1, num_result=10):
|
|
193 |
"data": {
|
194 |
"q": translated_query,
|
195 |
"domain": "google.com",
|
196 |
-
"loc": country,
|
197 |
"lang": COUNTRY_LANGUAGES.get(country, "en"),
|
198 |
"device": "desktop",
|
199 |
-
"serp_type": "web",
|
200 |
"page": "1",
|
|
|
201 |
"verbatim": "0",
|
202 |
-
"gfilter": "0"
|
203 |
-
"num_result": "10" # num_result๋ก ๋ณ๊ฒฝ
|
204 |
}
|
205 |
}
|
206 |
|
@@ -214,7 +213,7 @@ def search_serphouse(query, country, page=1, num_result=10):
|
|
214 |
response = requests.post(url, json=payload, headers=headers)
|
215 |
print("Request payload:", json.dumps(payload, indent=2, ensure_ascii=False))
|
216 |
print("Response status:", response.status_code)
|
217 |
-
print("
|
218 |
|
219 |
response.raise_for_status()
|
220 |
return {"results": response.json(), "translated_query": translated_query}
|
@@ -232,24 +231,26 @@ def format_results_from_raw(response_data):
|
|
232 |
results = response_data["results"]
|
233 |
translated_query = response_data["translated_query"]
|
234 |
|
235 |
-
|
236 |
-
|
|
|
237 |
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", []
|
238 |
|
239 |
articles = []
|
240 |
-
for idx, result in enumerate(
|
241 |
articles.append({
|
242 |
"index": idx,
|
243 |
"title": result.get("title", "์ ๋ชฉ ์์"),
|
244 |
-
"link": result.get("
|
245 |
"snippet": result.get("snippet", "๋ด์ฉ ์์"),
|
246 |
-
"channel": result.get("
|
247 |
-
"time": result.get("
|
248 |
-
"image_url": result.get("
|
249 |
"translated_query": translated_query
|
250 |
})
|
251 |
return "", articles
|
252 |
except Exception as e:
|
|
|
253 |
return f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}", []
|
254 |
|
255 |
def serphouse_search(query, country):
|
|
|
184 |
def search_serphouse(query, country, page=1, num_result=10):
|
185 |
url = "https://api.serphouse.com/serp/live"
|
186 |
|
|
|
187 |
translated_query = translate_query(query, country)
|
188 |
print(f"Original query: {query}")
|
189 |
print(f"Translated query: {translated_query}")
|
|
|
192 |
"data": {
|
193 |
"q": translated_query,
|
194 |
"domain": "google.com",
|
195 |
+
"loc": country,
|
196 |
"lang": COUNTRY_LANGUAGES.get(country, "en"),
|
197 |
"device": "desktop",
|
198 |
+
"serp_type": "web",
|
199 |
"page": "1",
|
200 |
+
"num": "10",
|
201 |
"verbatim": "0",
|
202 |
+
"gfilter": "0"
|
|
|
203 |
}
|
204 |
}
|
205 |
|
|
|
213 |
response = requests.post(url, json=payload, headers=headers)
|
214 |
print("Request payload:", json.dumps(payload, indent=2, ensure_ascii=False))
|
215 |
print("Response status:", response.status_code)
|
216 |
+
print("Full response content:", response.text) # ์ ์ฒด ์๋ต ๋ด์ฉ ์ถ๋ ฅ
|
217 |
|
218 |
response.raise_for_status()
|
219 |
return {"results": response.json(), "translated_query": translated_query}
|
|
|
231 |
results = response_data["results"]
|
232 |
translated_query = response_data["translated_query"]
|
233 |
|
234 |
+
# ์๋ต ๊ตฌ์กฐ ๋ณ๊ฒฝ์ ๋ฐ๋ฅธ ์์
|
235 |
+
search_results = results.get('results', {}).get('organic_results', []) # organic_results๋ก ๋ณ๊ฒฝ
|
236 |
+
if not search_results:
|
237 |
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", []
|
238 |
|
239 |
articles = []
|
240 |
+
for idx, result in enumerate(search_results, 1):
|
241 |
articles.append({
|
242 |
"index": idx,
|
243 |
"title": result.get("title", "์ ๋ชฉ ์์"),
|
244 |
+
"link": result.get("link", "#"),
|
245 |
"snippet": result.get("snippet", "๋ด์ฉ ์์"),
|
246 |
+
"channel": result.get("source", "์ ์ ์์"),
|
247 |
+
"time": result.get("date", "์ ์ ์๋ ์๊ฐ"),
|
248 |
+
"image_url": result.get("thumbnail", ""),
|
249 |
"translated_query": translated_query
|
250 |
})
|
251 |
return "", articles
|
252 |
except Exception as e:
|
253 |
+
print(f"Format error: {str(e)}") # ๋๋ฒ๊น
์ ์ํ ์๋ฌ ์ถ๋ ฅ ์ถ๊ฐ
|
254 |
return f"๊ฒฐ๊ณผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}", []
|
255 |
|
256 |
def serphouse_search(query, country):
|