Created
January 7, 2022 21:00
-
-
Save techb/0cf3c1893ab7fcd452e567ff8db59964 to your computer and use it in GitHub Desktop.
gets the cites associated with the given zipcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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