From 675b4e330c642c4f3f6e1d0eff3696dfc67baf45 Mon Sep 17 00:00:00 2001 From: Tim Head Date: Tue, 18 Nov 2014 07:22:28 +0100 Subject: [PATCH] Started a JSON API --- api.py | 26 ++++++++++++++++++++++++++ app.py | 1 + 2 files changed, 27 insertions(+) create mode 100644 api.py diff --git a/api.py b/api.py new file mode 100644 index 0000000..ad6a497 --- /dev/null +++ b/api.py @@ -0,0 +1,26 @@ +import bottle +from bottle import get, run, template + +import thesethreewords as these + + +@get("/v1/hash/,.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/.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)) diff --git a/app.py b/app.py index 7264406..5c3c5c9 100755 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ from bottle import ( ) import thesethreewords as these +import api as json_api @get('/')