Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,43 +5,45 @@ import os
|
|
5 |
from datetime import datetime, timedelta
|
6 |
|
7 |
API_KEY = os.getenv("SERPHOUSE_API_KEY")
|
|
|
|
|
8 |
|
9 |
COUNTRY_LOCATIONS = {
|
10 |
-
"United States": "
|
11 |
-
"United Kingdom": "
|
12 |
-
"Canada": "
|
13 |
-
"Australia": "2147714",
|
14 |
-
"Germany": "2950159",
|
15 |
-
"France": "2988507",
|
16 |
-
"Japan": "1850147",
|
17 |
-
"South Korea": "1835848",
|
18 |
-
"China": "
|
19 |
-
"India": "
|
20 |
-
"Brazil": "3448439",
|
21 |
-
"Mexico": "3530597",
|
22 |
-
"Russia": "524901",
|
23 |
-
"Italy": "3169070",
|
24 |
-
"Spain": "3117735",
|
25 |
-
"Netherlands": "2759794",
|
26 |
-
"Singapore": "1880252",
|
27 |
-
"Hong Kong": "1819729"
|
28 |
}
|
29 |
|
30 |
-
MAJOR_COUNTRIES = list(COUNTRY_LOCATIONS.keys())
|
31 |
|
32 |
-
|
|
|
33 |
url = "https://api.serphouse.com/serp/live"
|
34 |
|
35 |
payload = {
|
36 |
"data": {
|
37 |
"q": query,
|
38 |
"domain": "google.com",
|
39 |
-
"loc_id": COUNTRY_LOCATIONS.get(country, "
|
40 |
"lang": "en",
|
41 |
"device": "desktop",
|
42 |
"serp_type": "news",
|
43 |
"page": "1",
|
44 |
-
"num": "10",
|
45 |
"verbatim": "0",
|
46 |
"gfilter": "0"
|
47 |
}
|
@@ -53,22 +55,15 @@ def search_serphouse(query, country, page=1, num_result=100):
|
|
53 |
"authorization": f"Bearer {API_KEY}"
|
54 |
}
|
55 |
|
56 |
-
# ๋๋ฒ๊น
์ ์ํ ์์ฒญ ๋ด์ฉ ์ถ๋ ฅ
|
57 |
-
print("Request payload:", json.dumps(payload, indent=2))
|
58 |
-
|
59 |
try:
|
60 |
response = requests.post(url, json=payload, headers=headers)
|
61 |
-
|
62 |
-
print("Response status:", response.status_code)
|
63 |
-
print("Response content:", response.text[:500]) # ์ฒ์ 500์๋ง ์ถ๋ ฅ
|
64 |
|
65 |
response.raise_for_status()
|
66 |
return response.json()
|
67 |
except requests.RequestException as e:
|
68 |
-
|
69 |
-
if hasattr(response, 'text'):
|
70 |
-
error_msg += f"\nResponse content: {response.text}"
|
71 |
-
return {"error": error_msg}
|
72 |
|
73 |
def format_results_from_raw(results):
|
74 |
if isinstance(results, dict) and "error" in results:
|
|
|
5 |
from datetime import datetime, timedelta
|
6 |
|
7 |
API_KEY = os.getenv("SERPHOUSE_API_KEY")
|
8 |
+
MAJOR_COUNTRIES = list(COUNTRY_LOCATIONS.keys())
|
9 |
+
|
10 |
|
11 |
COUNTRY_LOCATIONS = {
|
12 |
+
"United States": "2643743", # London, UK (์์)
|
13 |
+
"United Kingdom": "2643743", # London, UK
|
14 |
+
"Canada": "6167865", # Toronto, Canada
|
15 |
+
"Australia": "2147714", # Sydney, Australia
|
16 |
+
"Germany": "2950159", # Berlin, Germany
|
17 |
+
"France": "2988507", # Paris, France
|
18 |
+
"Japan": "1850147", # Tokyo, Japan
|
19 |
+
"South Korea": "1835848", # Seoul, South Korea
|
20 |
+
"China": "1796236", # Shanghai, China
|
21 |
+
"India": "1275339", # Mumbai, India
|
22 |
+
"Brazil": "3448439", # Sao Paulo, Brazil
|
23 |
+
"Mexico": "3530597", # Mexico City, Mexico
|
24 |
+
"Russia": "524901", # Moscow, Russia
|
25 |
+
"Italy": "3169070", # Rome, Italy
|
26 |
+
"Spain": "3117735", # Madrid, Spain
|
27 |
+
"Netherlands": "2759794", # Amsterdam, Netherlands
|
28 |
+
"Singapore": "1880252", # Singapore
|
29 |
+
"Hong Kong": "1819729" # Hong Kong
|
30 |
}
|
31 |
|
|
|
32 |
|
33 |
+
|
34 |
+
def search_serphouse(query, country, page=1, num_result=10):
|
35 |
url = "https://api.serphouse.com/serp/live"
|
36 |
|
37 |
payload = {
|
38 |
"data": {
|
39 |
"q": query,
|
40 |
"domain": "google.com",
|
41 |
+
"loc_id": COUNTRY_LOCATIONS.get(country, "2643743"), # ๊ธฐ๋ณธ๊ฐ์ London์ผ๋ก ์ค์
|
42 |
"lang": "en",
|
43 |
"device": "desktop",
|
44 |
"serp_type": "news",
|
45 |
"page": "1",
|
46 |
+
"num": "10",
|
47 |
"verbatim": "0",
|
48 |
"gfilter": "0"
|
49 |
}
|
|
|
55 |
"authorization": f"Bearer {API_KEY}"
|
56 |
}
|
57 |
|
|
|
|
|
|
|
58 |
try:
|
59 |
response = requests.post(url, json=payload, headers=headers)
|
60 |
+
print("Request payload:", json.dumps(payload, indent=2)) # ๋๋ฒ๊น
์ฉ
|
61 |
+
print("Response status:", response.status_code) # ๋๋ฒ๊น
์ฉ
|
|
|
62 |
|
63 |
response.raise_for_status()
|
64 |
return response.json()
|
65 |
except requests.RequestException as e:
|
66 |
+
return {"error": f"Error: {str(e)}"}
|
|
|
|
|
|
|
67 |
|
68 |
def format_results_from_raw(results):
|
69 |
if isinstance(results, dict) and "error" in results:
|