-
Notifications
You must be signed in to change notification settings - Fork 1
/
yelp_api_galleries.py
53 lines (42 loc) · 1.53 KB
/
yelp_api_galleries.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import rauth
import pprint
import json
#import yelp_api_key as keys;
#See the official Yelp API for more details:
#http://www.yelp.com/developers/documentation
NUM_REQUESTS = 10
def get_search_parameters(latitude, longitude, offset):
params = {}
params["term"] = "art galleries"
params["ll"] = "{},{}".format(str(latitude),str(longitude))
params["radius_filter"] = "1300" # search radius in meters
params["limit"] = str(NUM_REQUESTS)
params["offset"] = offset
return params
def get_results(params):
session = rauth.OAuth1Session(
consumer_key = os.environ.get('HK_CONSUMER_KEY'),
consumer_secret = os.environ.get('HK_CONSUMER_SECRET'),
access_token = os.environ.get('HK_TOKEN'),
access_token_secret = os.environ.get('HK_TOKEN_SECRET'),
# consumer_key = consumer_key,
# consumer_secret = consumer_secret,
# access_token = token,
# access_token_secret = token_secret,
)
request = session.get("http://api.yelp.com/v2/search", params=params)
data = request.json()
session.close()
return data
def main(latitude, longitude):
locations = [(latitude, longitude),]
api_calls_galleries = []
offset = 0
for offset in range(0, 60, NUM_REQUESTS):
for latitude,longitude in locations:
params = get_search_parameters(latitude, longitude, offset)
offset += NUM_REQUESTS
api_calls_galleries.append(get_results(params))
print api_calls_galleries
return api_calls_galleries