-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathyelpapi.py
More file actions
46 lines (30 loc) · 1.13 KB
/
yelpapi.py
File metadata and controls
46 lines (30 loc) · 1.13 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
import json
import requests
from requests_oauthlib import OAuth1
consumer_key= 'NZTJrWhij8kemtAXmfyhyA'
consumer_secret = 'JtcAesDkKuNltcKdwR7NEaUkgm8'
token = 'TCipoxU_lYo55-F3rS10XdnN6f-3-KQI'
token_secret = '5gAZ99Arn2x_LIOVM25AWy8H84c'
url ='https://api.yelp.com/v2/search?term=food&location=San+Francisco'
r = requests.get(url, auth=auth)
def do_search(term='Food', location='San Francisco'):
base_url = 'https://api.yelp.com/v2/search'
term = term.replace(' ', '+')
location = location.replace(' ', '+')
url = "{base_url}?term={term}&location={location}".format(base_url=base_url,
term=term,
location=location)
auth = OAuth1(consumer_key,
consumer_secret,
token,
token_secret)
r = requests.get(url, auth=auth)
return r.json(), r.text
json_data, text_data = do_search()
python_data = json.loads(text_data)
print(json.dumps(json_data, indent=4, sort_keys=True))
for i in json_data['businesses']:
print(i["name"])
print(i["phone"])
print(i["location"]["display_address"])
print(i["location"]["city"])