Mercurial > hg > GlobalNeighbors
comparison globalneighbors/web.py @ 20:2fef925fbf37
display country + population in autocomplete drop down
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 25 Jun 2017 16:12:08 -0700 |
parents | 21095c9006e5 |
children | e69cb496324e |
comparison
equal
deleted
inserted
replaced
19:811adc9736eb | 20:2fef925fbf37 |
---|---|
14 from paste.urlparser import StaticURLParser | 14 from paste.urlparser import StaticURLParser |
15 from webob import Request, Response, exc | 15 from webob import Request, Response, exc |
16 from wsgiref import simple_server | 16 from wsgiref import simple_server |
17 from .locations import locations | 17 from .locations import locations |
18 from .locations import city_dict | 18 from .locations import city_dict |
19 from .neighbors import read_neighbors_file | |
19 from .read import read_cities | 20 from .read import read_cities |
20 from .read import read_city_list | 21 from .read import read_city_list |
21 from .schema import fields | 22 from .schema import fields |
22 from .schema import name | 23 from .schema import name |
23 from .template import template_dir | 24 from .template import template_dir |
111 class GlobalHandler(Handler): | 112 class GlobalHandler(Handler): |
112 """WSGI HTTP Handler""" | 113 """WSGI HTTP Handler""" |
113 | 114 |
114 content_type = 'text/html' | 115 content_type = 'text/html' |
115 | 116 |
116 def __init__(self, datafile, template_dir=template_dir): | 117 def __init__(self, |
118 datafile, | |
119 neighbors_file=None, | |
120 template_dir=template_dir): | |
117 | 121 |
118 | 122 |
119 # parse data | 123 # parse data |
120 self.datafile = datafile | 124 self.datafile = datafile |
121 self.cities = read_city_list(self.datafile, | 125 self.cities = read_city_list(self.datafile, |
122 fields=fields) | 126 fields=fields) |
123 self.locations = locations(self.cities) | 127 self.locations = locations(self.cities) |
128 if neighbors_file: | |
129 pass # TODO | |
124 | 130 |
125 # get country codes | 131 # get country codes |
126 self.country_codes = sorted(set([city['country code'] | 132 self.country_codes = sorted(set([city['country code'] |
127 for city in self.cities | 133 for city in self.cities |
128 if city['country code']])) | 134 if city['country code']])) |
178 type=int, default=8080, | 184 type=int, default=8080, |
179 help="port to serve on") | 185 help="port to serve on") |
180 parser.add_argument('--hostname', dest='hostname', | 186 parser.add_argument('--hostname', dest='hostname', |
181 default='localhost', | 187 default='localhost', |
182 help="host name [DEFAULT: %(default)s]") | 188 help="host name [DEFAULT: %(default)s]") |
189 parser.add_argument('--neighbors', dest='neighbors_file', | |
190 help="file for nearest neighbors") | |
183 options = parser.parse_args(args) | 191 options = parser.parse_args(args) |
184 | 192 |
185 # instantiate WSGI handler | 193 # instantiate WSGI handler |
186 app = GlobalHandler(datafile=options.cities) | 194 app = GlobalHandler(datafile=options.cities, |
195 neighbors_file=options.neighbors_file) | |
187 | 196 |
188 # wrap it in a static file server | 197 # wrap it in a static file server |
189 app = PassthroughFileserver(app) | 198 app = PassthroughFileserver(app) |
190 | 199 |
191 print ("Serving on http://{hostname}:{port}/".format(**options.__dict__)) | 200 print ("Serving on http://{hostname}:{port}/".format(**options.__dict__)) |