Skip to content

Instantly share code, notes, and snippets.

@ef1500
Created January 10, 2023 18:11
Show Gist options
  • Save ef1500/83332bdb7b98419a1688ce1e96538436 to your computer and use it in GitHub Desktop.
Save ef1500/83332bdb7b98419a1688ce1e96538436 to your computer and use it in GitHub Desktop.
Get Zip Code Information
# zipinfo.py -c US -z 58906
import requests
import argparse
BASE_URL = "https://zip-api.eu/api/v1/info/"
class ZipInfo:
def __init__(self, zipcode, country_code):
self.zipcode = zipcode
self.country_code = country_code.upper()
def get_zip_info(self):
zip_request = requests.get(f"{BASE_URL}{self.country_code}-{self.zipcode}", timeout=15)
zip_request = zip_request.json()
for i,key in zip_request.items():
print(f"{i} : {key}")
parser = argparse.ArgumentParser(prog="Get Zip Code Information")
parser.add_argument("-c", "--countrycode", type=str, help="Country to get info from")
parser.add_argument("-z", "--zipcode", type=str, help="Zip Code")
args = parser.parse_args()
zInfo = ZipInfo(args.zipcode, args.countrycode)
zInfo.get_zip_info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment