Module Expr Str Assign NameStore Str Import alias Import alias Import alias Import alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias alias alias ImportFrom alias ImportFrom alias Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Num keyword Str ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr TryExcept body With Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Str NameStore body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler body Assign AttributeStore NameLoad attr Dict decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body If CompareNotEq AttributeLoad NameLoad attr Num body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad orelse TryExcept body Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore ListLoad If CompareGt Call NameLoad SubscriptLoad NameLoad Index Str Num body For NameStore SubscriptLoad SubscriptLoad SubscriptLoad NameLoad Index Str Index Num Index Str body For NameStore SubscriptLoad NameLoad Index Str body If CompareIn NameLoad TupleLoad Str Str Str body Expr Call AttributeLoad NameLoad attr NameLoad Break Assign SubscriptStore AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr NameLoad handlers ExceptHandler body Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Expr Call NameLoad decorator_list With Call AttributeLoad NameLoad attr NameLoad NameStore body FunctionDef arguments args NameParam defaults body Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Num For NameStore Call NameLoad Call NameLoad NameLoad body Assign NameStore SubscriptLoad NameLoad Index NameLoad If CompareNotIn AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign TupleStore NameStore NameStore TupleLoad Call NameLoad AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr NameLoad NameLoad If CompareGt BinOpDiv NameLoad BinOpSub BinOpAdd Num Call AttributeLoad NameLoad attr NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Expr Call AttributeLoad NameLoad attr Str Return Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd Call AttributeLoad NameLoad attr Num Call NameLoad NameLoad SubscriptLoad NameLoad Slice NameLoad AugAssignAdd NameStore Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpMod Str TupleLoad NameLoad NameLoad keyword Call NameLoad NameLoad NameLoad Call AttributeLoad NameLoad attr keyword Str decorator_list Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore BinOpAdd AttributeLoad AttributeLoad NameLoad attr attr Str TryExcept body With Call NameLoad NameLoad Str NameStore body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad AttributeLoad NameLoad attr attr handlers ExceptHandler body Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr NameLoad decorator_list decorator_list FunctionDef arguments args defaults body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr Assign NameStore Call NameLoad Assign NameStore Call NameLoad NameLoad NameLoad FunctionDef arguments args defaults body Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Return Num decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr Call NameLoad
N/A N/A Parses the cities1000.txt geonames database and uses google maps
API to lookup locality, administrative_area_level_1 and country using
the latitude and longitude listed with each city.

Datafile sourced from: http://download.geonames.org/.

The contents of each lookup are written to a JSON-encoded file which
is re-read on each invocation. Only cities in cities1000.txt which are
not already accounted-for in the JSON-encoded file are looked up to
avoid duplicative queries.

Usage:

% python resources/geonames/geolookup.py --cityfile=cities1000.txt --lookupdb=lookup.json

 N/A __author__ spencer@emailscrubbed.com (Spencer Kimball) N/A json N/A logging N/A os N/A sys N/A time functools partial operator attrgetter tornado httpclient ioloop options viewfinder.backend.base util viewfinder.resources.geodata.geoprocessor GeoProcessor N/A N/A N/A options define lookupdb default lookup.json help JSON output file containing lookup data N/A N/A N/A options define query_rate default 10 help allowed queries per second to google maps GeoLookup N/A object N/A N/A Main class for geolookup. Handles initial parse of JSON data
  file and spawns async HTTP queries to google maps API.
   __init__ N/A N/A self io_loop geoproc N/A N/A N/A N/A self _io_loop io_loop N/A N/A self _geoproc geoproc N/A N/A self _http_client N/A N/A httpclient AsyncHTTPClient N/A N/A N/A N/A open N/A N/A options options lookupdb r rf N/A N/A N/A self _lookup_db N/A N/A json load rf N/A N/A N/A N/A N/A self _lookup_db N/A N/A RefreshDB N/A N/A self callback N/A N/A N/A Refreshes the lookup database by iterating over all cities in
    the geoprocessor and querying google maps for address components
    for any that are missing.
     _OnLookup N/A N/A city barrier_cb response N/A N/A N/A N/A N/A response code 200 N/A N/A N/A N/A logging error N/A error in google maps API query: %s response N/A N/A N/A N/A json_response N/A N/A json loads N/A response body N/A components N/A N/A N/A N/A len N/A json_response N/A results 0 N/A N/A comp N/A N/A N/A json_response N/A results N/A 0 N/A address_components N/A N/A t N/A comp N/A types N/A N/A N/A t N/A locality administrative_area_level_1 country N/A N/A N/A N/A components append comp N/A N/A N/A N/A self _lookup_db N/A N/A city id components N/A N/A N/A N/A N/A N/A logging exception N/A unable to parse google maps API response: %s N/A response body N/A N/A barrier_cb N/A N/A N/A N/A util Barrier callback b N/A _ProcessCities N/A N/A cities N/A N/A N/A start_time N/A N/A time time N/A lookup_count 0 N/A index N/A xrange N/A len cities N/A N/A city N/A cities N/A index N/A N/A N/A city id N/A self _lookup_db N/A N/A N/A lat lon N/A N/A float N/A city lat N/A float N/A city lon N/A N/A N/A logging info N/A looking up %s (%f, %f) via google maps API N/A N/A city name lat lon N/A N/A N/A lookup_count N/A N/A 1.0 N/A N/A time time start_time N/A N/A options options query_rate N/A N/A N/A N/A logging info pausing to slow API query rate N/A N/A N/A N/A self _io_loop add_timeout N/A N/A N/A time time 1.0 N/A partial _ProcessCities N/A cities N/A index N/A lookup_count 1 N/A N/A N/A N/A self _http_client fetch N/A http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false N/A lat lon callback N/A partial _OnLookup city N/A N/A b Callback method GET N/A N/A cities N/A N/A N/A self _geoproc GetCities N/A N/A _ProcessCities cities N/A SaveDB N/A N/A self N/A N/A N/A Saves the database to disk by writing to a temporary file and
    then renames.
     N/A tmp_file N/A N/A N/A options options lookupdb .bak N/A N/A N/A N/A open tmp_file w wf N/A N/A N/A N/A json dump N/A self _lookup_db wf N/A N/A N/A os rename tmp_file N/A N/A options options lookupdb N/A N/A N/A N/A N/A N/A logging exception unable to write lookup database N/A N/A N/A os unlink tmp_file N/A N/A main N/A N/A N/A N/A N/A io_loop N/A N/A N/A ioloop IOLoop instance N/A N/A N/A options parse_command_line N/A geoproc N/A GeoProcessor N/A geolookup N/A GeoLookup io_loop geoproc _OnRefresh N/A N/A N/A N/A N/A N/A N/A geolookup SaveDB N/A N/A N/A io_loop stop N/A N/A N/A N/A geolookup RefreshDB _OnRefresh N/A N/A N/A io_loop start N/A 0 N/A N/A N/A __name__ __main__ N/A N/A N/A N/A sys exit N/A main