Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
820f316
ยท
verified ยท
1 Parent(s): decbbc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -32
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": "1026201", # Alba,Texas,United States
11
- "United Kingdom": "2635167", # Birmingham,England,United Kingdom
12
- "Canada": "5907364", # Burnaby,British Columbia,Canada
13
- "Australia": "2147714", # Sydney,New South Wales,Australia
14
- "Germany": "2950159", # Berlin,Berlin,Germany
15
- "France": "2988507", # Paris,รŽle-de-France,France
16
- "Japan": "1850147", # Tokyo,Tokyo,Japan
17
- "South Korea": "1835848", # Seoul,Seoul,South Korea
18
- "China": "1816670", # Beijing,Beijing,China
19
- "India": "1261481", # New Delhi,Delhi,India
20
- "Brazil": "3448439", # Sรฃo Paulo,Sรฃo Paulo,Brazil
21
- "Mexico": "3530597", # Mexico City,Mexico City,Mexico
22
- "Russia": "524901", # Moscow,Moscow,Russia
23
- "Italy": "3169070", # Rome,Lazio,Italy
24
- "Spain": "3117735", # Madrid,Madrid,Spain
25
- "Netherlands": "2759794", # Amsterdam,North Holland,Netherlands
26
- "Singapore": "1880252", # Singapore,Central Singapore,Singapore
27
- "Hong Kong": "1819729" # Hong Kong,Central and Western District,Hong Kong
28
  }
29
 
30
- MAJOR_COUNTRIES = list(COUNTRY_LOCATIONS.keys())
31
 
32
- def search_serphouse(query, country, page=1, num_result=100):
 
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, "1026201"),
40
  "lang": "en",
41
  "device": "desktop",
42
  "serp_type": "news",
43
  "page": "1",
44
- "num": "10", # API ์ œํ•œ์— ๋งž์ถฐ ์ˆ˜์ •
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
- error_msg = f"Error: {str(e)}"
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: