-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
53 lines (45 loc) · 1.46 KB
/
app.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
from flask import Flask, request
from flask_restful import Resource, Api
from json import dumps
app = Flask(__name__)
api = Api(app)
from pprint import pprint
from yelpapi import YelpAPI
import json as JSON
import time
yelpKeys = JSON.load(open('keys.json'))
yelp_api = YelpAPI(yelpKeys["yelp_consumerKey"], yelpKeys["yelp_consumerSecret"], yelpKeys["yelp_token"], yelpKeys["yelp_tokenSecret"])
@app.route('/business')
def api_business():
lati = request.args['lat']
lngi = request.args['lng']
cati = request.args['cat']
print str(lati)
print str(lngi)
print lati
print lngi
features = []
total = 500
off = 0
try:
while off+20 < total:
time.sleep(1)
response = yelp_api.search_query(ll=str(lati)+','+str(lngi),category_filter=str(cati), offset=off)
if response['total'] > 500:
total = 500
else:
response['total']
print off
print total
if off+20 <= total:
off = off+20
for business in response['businesses']:
lat = business['location']['coordinate']['latitude']
lng = business['location']['coordinate']['longitude']
features.append({"lat":lat, "lng":lng, "weight":business['rating'] })
return JSON.dumps(features)
except Exception, e:
raise e
return JSON.dumps(features)
if __name__ == '__main__':
app.run()