-
Notifications
You must be signed in to change notification settings - Fork 0
/
luncher.py
53 lines (46 loc) · 1.65 KB
/
luncher.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
from flask import render_template
from flask import request
app = Flask(__name__)
from lib.foursquare import Foursquare, FoursquareAuth
import settings
client_id=settings.CLIENT_ID
client_secret=settings.CLIENT_SECRET
category_id=settings.CATEGORY_ID
@app.route('/', methods=['POST', 'GET'])
def index():
auth=FoursquareAuth(client_id, client_secret)
foursq=Foursquare(auth)
venues=None
error=None
lat=''
lon=''
if request.method == 'POST':
lat=request.form.get('lat', '')
lon=request.form.get('lon', '')
radius=request.form.get('radius', 500)
cid=request.form.get('cid', category_id)
latlon='%s.%s,%s.%s' % (lat.split('.')[0],
lat.split('.')[1],
lon.split('.')[0],
lon.split('.')[1],)
try:
res=foursq.request('venues',
aspect='search',
ll=latlon,
radius=radius,
categoryId=cid)
venues=res['response']['venues']
except Exception, e:
error='Connection error - %s ' % e
title='Where can I go for lunch today?'
sitename='lunchlotto'
return render_template('base.html', venues=venues, error=error, lat=lat, lon=lon, title=title, sitename=sitename)
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/imprint')
def imprint():
return render_template('imprint.html')
if __name__ == '__main__':
app.run(debug=True)