-
Notifications
You must be signed in to change notification settings - Fork 0
/
YelpSearch.py
38 lines (30 loc) · 1.01 KB
/
YelpSearch.py
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
import json
import requests
def getRequest(term, location):
terms = "term=" + term
locations = "location=" + location
url = "https://api.yelp.com/v3/businesses/search?" + terms + "&" + locations
api_key = "key"
headers = {
'Authorization': 'Bearer %s' % api_key,
}
url_params = {}
response = requests.request('GET', url, headers=headers, params=url_params)
json_obj = json.loads(response.content.decode("utf-8"))
results = json_obj.get("businesses")
delkaPole = len(results)
novePole = []
for i in results:
objekt = {}
objekt["id"] = i.get("id")
objekt["name"] = i.get("name")
objekt["phone"] = i.get("phone")
objekt["rating"] = i.get("rating")
objekt["url"] = i.get("url")
objekt["location"] = i.get("location")
novePole.append(objekt)
return results
if __name__ == '__main__': # Main method
terms = "gluten-free"
locations = "Nove Mesto, Praha"
print(getRequest(terms, locations))