Mercurial > hg > GlobalNeighbors
diff globalneighbors/web.py @ 1:1b94f3bf97e5
* limit distance function
* start gridding
* improve unicode handling
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:02:14 -0700 |
parents | 5dba84370182 |
children | 316e1d54ffd4 |
line wrap: on
line diff
--- a/globalneighbors/web.py Sat Jun 24 12:03:39 2017 -0700 +++ b/globalneighbors/web.py Sat Jun 24 14:02:14 2017 -0700 @@ -19,6 +19,23 @@ from .schema import name +def autocomplete(cities, startswith=None): + """autocomplete function for city names""" + ### TODO: sort once, ahead of time + + if startswith: + retval = [] + for i in cities: + try: + if i[name].startswith(startswith): + retval.append(i[name]) + except Exception as e: + import pdb; pdb.set_trace() + return sorted(retval) + else: + return sorted([i[name] for i in cities]) + + class Handler(object): """base class for HTTP handler""" @@ -45,12 +62,8 @@ def cities(self, startswith=None): """return list of cities""" - - if startswith: - return sorted([i[name] for i in self._cities - if i[name].startswith(startswith)]) - else: - return sorted([i[name] for i in self._cities]) + return autocomplete(self._cities, + startswith=startswith) def GET(self, request): return Response(content_type=self.content_type,