Skip to content

Instantly share code, notes, and snippets.

@techb
Created January 7, 2022 21:00
Show Gist options
  • Save techb/0cf3c1893ab7fcd452e567ff8db59964 to your computer and use it in GitHub Desktop.
Save techb/0cf3c1893ab7fcd452e567ff8db59964 to your computer and use it in GitHub Desktop.
gets the cites associated with the given zipcode
# requires uszipcode
# $ pip install uszipcode
# zip.csv is a list of only zipcodes, one per each line
from sqlalchemy.sql.operators import op
from uszipcode import SearchEngine
from pprint import pprint
rtn = []
zips = []
with open("zip.csv", "r") as f:
r = f.read()
zips = r.split("\n")
engine = SearchEngine()
for z in zips:
data = engine.by_zipcode(int(z))
rtn.append(data.zipcode + "," + data.major_city)
with open("out.csv", "w") as o:
o.write('\n'.join(rtn))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment