-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.py
58 lines (45 loc) · 1.34 KB
/
hello.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
52
53
54
55
56
57
58
import rauth
import pandas as pd
from config import shush
print 'hello world'
def get_search_parameters(term, city):
#See the Yelp API for more details
params = {}
params["term"] = term
params["location"] = city
params["radius_filter"] = "4000"
params["limit"] = "20"
return params
def get_results(params):
#Obtain these from Yelp's manage access page
consumer_key = shush["key"]
consumer_secret = shush["secret"]
token = shush["token"]
token_secret = shush["token_secret"]
session = rauth.OAuth1Session(
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)
#Transforms the JSON API response into a Python dictionary
data = request.json()
session.close()
return data
locations = ['San Fransisco, CA', 'New York, NY', 'Austin, TX']
search = 'ice cream sandwiches'
api_calls = []
print 'hello, searching for ' + search
for loc in locations:
print loc
params = get_search_parameters(search, loc)
out = get_results(params)
for o in out:
print o["id"]
print o["rating"]
print o["snippet_text"]
api_calls = api_calls + [out]
#Be a good internet citizen and rate-limit yourself
time.sleep(1.0)
print api_calls
##Do other processing