Skip to content

Commit

Permalink
updated zipcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
john-zither committed Dec 1, 2024
1 parent 402b02e commit 1cb9f42
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions scripts/build_zipcode_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import eeweather
import collections
from pprint import pprint
from thermostat.stations import get_closest_station_by_zipcode
from thermostat.stations import get_closest_station_by_zipcode, USA_ISO_COUNTRY_CODES
from thermostat.climate_zone import retrieve_climate_zone
from multiprocessing import Pool, cpu_count
from functools import partial
Expand All @@ -20,22 +20,21 @@ def get_station_climate_zone(zipcode_obj):
zipcode = zipcode_obj
station = get_closest_station_by_zipcode(zipcode)
climate_zone_nt = retrieve_climate_zone(zipcode)
except Exception:
except Exception as e:
return None, None, None
return zipcode, station, climate_zone_nt.climate_zone


def main():
def main(countries=USA_ISO_COUNTRY_CODES):
"""This code looks up all available zip codes and generates a data file with station and climate zone lookups"""
zipcode_lookup = {}

p = Pool()
multiprocess_func_partial = partial(
get_station_climate_zone,
)
nomi = pgeocode.Nominatim('US')
us_zipcodes = nomi._data
result_list = p.imap(multiprocess_func_partial, us_zipcodes['postal_code'].tolist())
us_zipcodes = sum((pgeocode.Nominatim(code)._data['postal_code'].tolist() for code in countries), [])
result_list = p.imap(multiprocess_func_partial, us_zipcodes)
p.close()
p.join()

Expand Down

0 comments on commit 1cb9f42

Please sign in to comment.