2014-11-17 10:44:55 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2014-11-17 14:44:39 +00:00
|
|
|
import bottle
|
2014-11-17 10:44:55 +00:00
|
|
|
from bottle import (
|
|
|
|
get,
|
|
|
|
run,
|
2014-11-18 09:10:18 +00:00
|
|
|
static_file,
|
2014-11-17 10:44:55 +00:00
|
|
|
template
|
|
|
|
)
|
|
|
|
|
|
|
|
import thesethreewords as these
|
2014-11-18 06:22:28 +00:00
|
|
|
import api as json_api
|
2014-11-17 10:44:55 +00:00
|
|
|
|
|
|
|
|
2014-11-18 09:10:18 +00:00
|
|
|
@get('/static/<filename:path>')
|
|
|
|
def serve_static(filename):
|
|
|
|
return static_file(filename, root='static')
|
|
|
|
|
|
|
|
|
2014-11-17 10:44:55 +00:00
|
|
|
@get('/')
|
|
|
|
def index():
|
|
|
|
return template('index', err=None)
|
|
|
|
|
2014-11-17 14:44:39 +00:00
|
|
|
|
2014-11-17 10:44:55 +00:00
|
|
|
@get('/<threewords>')
|
|
|
|
def showMap(threewords):
|
|
|
|
try:
|
|
|
|
lat, lng = these.decode(threewords)
|
2014-11-17 15:59:10 +00:00
|
|
|
return template('map', lat=lat, lng=lng, threewords=threewords)
|
2014-11-17 10:44:55 +00:00
|
|
|
except:
|
|
|
|
return template('index',
|
|
|
|
err="Could not find location {}".format(threewords))
|
|
|
|
|
|
|
|
|
2014-11-18 09:10:18 +00:00
|
|
|
# API
|
|
|
|
@get('/api/<lat:float>,<lng:float>')
|
|
|
|
def latLngToHash(lat, lng):
|
|
|
|
try:
|
|
|
|
three = these.three_words((lat,lng))
|
|
|
|
six = these.six_words((lat,lng))
|
|
|
|
return {'three': three, 'six': six}
|
|
|
|
except:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
@get('/api/<threewords>')
|
|
|
|
def hashToLatLng(threewords):
|
|
|
|
try:
|
|
|
|
lat,lng = these.decode(threewords)
|
|
|
|
return {"lat": lat, "lng": lng}
|
|
|
|
except:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-17 10:44:55 +00:00
|
|
|
if __name__ == '__main__':
|
2014-11-17 14:42:06 +00:00
|
|
|
run(host='localhost', port=8080)
|
|
|
|
|
|
|
|
app = bottle.default_app()
|