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_extract_api_client() text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." \ "\r\nLos Vegas, Nevada." \ "\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho." # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/us-extract-api#http-request-input-fields lookup = Lookup() lookup.text = text lookup.aggressive = True lookup.addresses_have_line_breaks = False lookup.addresses_per_line = 1 result = client.send(lookup) metadata = result.metadata print('Found {} addresses.'.format(metadata.address_count)) print('{} of them were valid.'.format(metadata.verified_count)) print() addresses = result.addresses print('Addresses: \r\n**********************\r\n') for address in addresses: print('"{}"\n'.format(address.text)) print('Verified? {}'.format(address.verified)) if len(address.candidates) > 0: print('\nMatches:') for candidate in address.candidates: print(candidate.delivery_line_1) print(candidate.last_line) print() else: print() print('**********************\n')
def verifyUserInput(): addr = request.args.get("text") auth_id = "4db04845-3fbe-8b38-d005-5dc10f75a80b" auth_token = "pAKyFrPrrfishQdMPgzU" credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_extract_api_client() lookup = ExtractLookup() lookup.text = addr lookup.aggressive = True lookup.addresses_have_line_breaks = False lookup.addresses_per_line = 1 result = client.send(lookup) metadata = result.metadata print("Found {} addresses.".format(metadata.address_count)) print("{} of them were valid.".format(metadata.verified_count)) print() return jsonify(metadata.verified_count)
def test_sending_fully_populated_lookup(self): capturing_sender = RequestCapturingSender() sender = URLPrefixSender('http://localhost/', capturing_sender) serializer = FakeSerializer(None) client = Client(sender, serializer) lookup = Lookup('1') lookup.html = True lookup.aggressive = True lookup.addresses_have_line_breaks = True lookup.addresses_per_line = 2 client.send(lookup) request = capturing_sender.request self.assertEqual('true', request.parameters['html']) self.assertEqual('true', request.parameters['aggressive']) self.assertEqual('true', request.parameters['addr_line_breaks']) self.assertEqual(2, request.parameters['addr_per_line'])
def varify_address(address_string): auth_id = "c7bce886-bfac-637c-31f2-dff34a511bf7" auth_token = "r895zvHWv7B9Ew1cmwTA" # 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_extract_api_client() text = address_string # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/us-extract-api#http-request-input-fields lookup = ExtractLookup() lookup.text = text lookup.aggressive = True lookup.addresses_have_line_breaks = False lookup.addresses_per_line = 1 result = client.send(lookup) metadata = result.metadata # print('Found {} addresses.'.format(metadata.address_count)) # print('{} of them were valid.'.format(metadata.verified_count)) # print() addresses = result.addresses for address in addresses: print('"{}"\n'.format(address.text)) print('Verified? {}'.format(address.verified)) data = {} if len(address.candidates) > 0: try: data['Ship-to Address'] = ( address.candidates[0].components.primary_number + ' ' + address.candidates[0].components.street_name + ' ' + address.candidates[0].components.street_suffix) try: data['Ship-to Address 2'] = ( address.candidates[0].components.secondary_designator + ' ' + address.candidates[0].components.secondary_number) except Exception as e: print('error in add 2') print(e) data['Ship-to Address 2'] = "" data['Ship-to City'] = ( address.candidates[0].components.city_name) data['Ship-to County'] = ( address.candidates[0].components.state_abbreviation) data['Ship-to Post-code'] = ( address.candidates[0].components.zipcode + '-' + address.candidates[0].components.plus4_code) data['Ship-to Country/Region Code'] = ('US') except Exception as e: return False return data return False # if __name__ == "__main__": # run()