Started a JSON API

This commit is contained in:
Tim Head 2014-11-18 07:22:28 +01:00
parent ff5d158a4e
commit 675b4e330c
2 changed files with 27 additions and 0 deletions

26
api.py Normal file
View File

@ -0,0 +1,26 @@
import bottle
from bottle import get, run, template
import thesethreewords as these
@get("/v1/hash/<lat:float>,<lng:float>.json")
def latlng_to_hash(lat, lng):
try:
three = these.three_words((lat,lng))
six = these.six_words((lat,lng))
return {"three": three, "six": six}
except:
return template('index',
err="Could not find location {}".format(threewords))
@get('/v1/hash/<threewords>.json')
def hash_to_latlng(threewords):
try:
lat,lng = these.decode(threewords)
return {"lat": lat, "lng": lng}
except:
return template('index',
err="Could not find location {}".format(threewords))

1
app.py
View File

@ -8,6 +8,7 @@ from bottle import (
)
import thesethreewords as these
import api as json_api
@get('/')