def getZipCode(cityName, stateName): auth_id = "64c1b167-5f64-f1ab-0898-5a13c92e2359" auth_token = "WfTDEo4wyzYEaOeoe3FV" # We recommend storing your secret keys in environment variables instead---it's safer! # auth_id = os.environ['SMARTY_AUTH_ID'] # auth_token = os.environ['SMARTY_AUTH_TOKEN'] credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_zipcode_api_client() # Documentation for input fields can be found at: # https://smartystreet.com/docs/us-zipcode-api#input-fields lookup = ZIPCodeLookup() lookup.input_id = "dfc33cb6-829e-4fea-aa1b-b6d6580f0817" # Optional ID from your system lookup.city = cityName lookup.state = stateName try: client.send_lookup(lookup) except exceptions.SmartyException as err: print(err) return result = lookup.result zipcodes = result.zipcodes cities = result.cities # for zipcode in zipcodes: # print("\nZIP Code: " + zipcode.zipcode) return zipcodes
def get_zip_code(self, town_info): lookup = Lookup() lookup.input_id = "dfc33cb6-829e-4fea-aa1b-b6d6580f0817" lookup.city = town_info["city"] lookup.state = town_info["state"] try: self._zip_client.send_lookup(lookup) except exceptions.SmartyException as err: print(err) return result_json = self._zip_lookup_to_json(lookup) result = result_json return result
def run(): # auth_id = "Your SmartyStreets Auth ID here" # auth_token = "Your SmartyStreets Auth Token here" # We recommend storing your secret keys in environment variables instead---it's safer! auth_id = os.environ['SMARTY_AUTH_ID'] auth_token = os.environ['SMARTY_AUTH_TOKEN'] credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_zipcode_api_client() # Documentation for input fields can be found at: # https://smartystreet.com/docs/us-zipcode-api#input-fields lookup = ZIPCodeLookup() lookup.input_id = "dfc33cb6-829e-4fea-aa1b-b6d6580f0817" # Optional ID from your system lookup.city = "Mountain View" lookup.state = "California" lookup.zipcode = "94043" try: client.send_lookup(lookup) except exceptions.SmartyException as err: print(err) return result = lookup.result zipcodes = result.zipcodes cities = result.cities for city in cities: print("\nCity: " + city.city) print("State: " + city.state) print("Mailable City: {}".format(city.mailable_city)) for zipcode in zipcodes: print("\nZIP Code: " + zipcode.zipcode) print("Latitude: {}".format(zipcode.latitude)) print("Longitude: {}".format(zipcode.longitude))