Mercurial > hg > GlobalNeighbors
diff globalneighbors/web.py @ 22:e69cb496324e
we have a data dump
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 25 Jun 2017 17:45:19 -0700 |
parents | 2fef925fbf37 |
children | 6891c5523b69 |
line wrap: on
line diff
--- a/globalneighbors/web.py Sun Jun 25 16:28:56 2017 -0700 +++ b/globalneighbors/web.py Sun Jun 25 17:45:19 2017 -0700 @@ -108,6 +108,19 @@ body=json.dumps(self.cities( startswith=request.GET.get('term')))) +class NeighborsHandler(Handler): + + content_type = 'application/json' + + def __init__(self, neighbors): + self.neighbors = neighbors + + def GET(self, request): + geoid = request.GET.get('geoid') + neighbors = self.neighbors.get(geoid, []) + return Response(content_type=self.content_type, + body=json.dumps(neighbors)) + class GlobalHandler(Handler): """WSGI HTTP Handler""" @@ -126,7 +139,9 @@ fields=fields) self.locations = locations(self.cities) if neighbors_file: - pass # TODO + self.neighbors = read_neighbors_file(neighbors_file) + else: + self.neighbors = None # get country codes self.country_codes = sorted(set([city['country code'] @@ -166,6 +181,8 @@ if not city: return variables = dict(city=city) + if self.neighbors: + import pdb; pdb.set_trace() return Response(content_type=self.content_type, body=self.citypage.render(variables)) except ValueError: