-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerpApiSearches.py
More file actions
44 lines (35 loc) · 1.11 KB
/
SerpApiSearches.py
File metadata and controls
44 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from serpapi import GoogleSearch
import secrets
def suggest_location(search_location):
params = {
"engine": "google",
"q": search_location + " attractions",
"api_key": secrets.serpapiKey
}
search = GoogleSearch(params)
results = search.get_dict()
print(results)
results_string = ""
if "top_sights" in results:
top_sights = results['top_sights']['sights']
print(top_sights)
sights_suggested = "Suggested places to visit:\n"
for i in top_sights:
sights_suggested += i['title'] + '\n'
print(sights_suggested)
results_string = sights_suggested
elif "popular_destinations" in results:
destinations = results["popular_destinations"]["destinations"]
destinations_string = "Suggested places to visit:"
for i in destinations:
destinations_string += i['title'] + "\n"
print(destinations_string)
results_string = destinations_string
else:
results_string = "No suggestions found."
if not results_string.strip():
results_string = "No suggestions found."
print("here")
return results_string
results = suggest_location("usa")
print(results)