def run(): auth_id = os.environ[ 'SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables auth_token = os.environ['SMARTY_AUTH_TOKEN'] credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_autocomplete_api_client() lookup = Lookup('4770 Lincoln Ave O') client.send(lookup) print('*** Result with no filter ***') print() for suggestion in lookup.result: print(suggestion.text) lookup.add_state_filter('IL') lookup.max_suggestions = 5 suggestions = client.send( lookup) # The client will also return the suggestions directly print() print('*** Result with some filters ***') for suggestion in suggestions: print(suggestion.text)
def autoCompleteSmartyAPI(): addr = request.args.get("address") auth_id = "4db04845-3fbe-8b38-d005-5dc10f75a80b" auth_token = "pAKyFrPrrfishQdMPgzU" credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_autocomplete_api_client() lookup = AutocompleteLookup(addr) client.send(lookup) local_res = [] for suggestion in lookup.result: local_res.append(suggestion.text) return jsonify(local_res)
def run(): # key = "Your SmartyStreets Key here" # hostname = "Your Hostname here" # We recommend storing your secret keys in environment variables instead---it's safer! key = os.environ['SMARTY_AUTH_WEB'] hostname = os.environ['SMARTY_WEBSITE_DOMAIN'] credentials = SharedCredentials(key, hostname) # auth_id = os.environ['SMARTY_AUTH_ID'] # token = os.environ['SMARTY_AUTH_TOKEN'] # credentials = StaticCredentials(auth_id, token) # The appropriate license values to be used for your subscriptions # can be found on the Subscriptions page of the account dashboard. # https://www.smartystreets.com/docs/cloud/licensing client = ClientBuilder(credentials).with_licenses( ["us-autocomplete-pro-cloud"]).build_us_autocomplete_pro_api_client() lookup = AutocompleteProLookup('1042 W Center') client.send(lookup) print('*** Result with no filter ***') print() for suggestion in lookup.result: print suggestion.street_line, suggestion.city, ",", suggestion.state # Documentation for input fields can be found at: # https://smartystreets.com/docs/us-autocomplete-api#http-request-input-fields lookup.add_state_filter('CO') lookup.add_state_filter('UT') lookup.add_city_filter('Denver') lookup.add_city_filter('Orem') lookup.add_state_preference('CO') lookup.add_state_preference('UT') lookup.add_city_preference('Denver') lookup.selected = '1042 W Center St Apt A (24) Orem UT 84057' lookup.max_results = 5 lookup.prefer_geo = geolocation_type.NONE lookup.prefer_ratio = 33 lookup.source = 'all' suggestions = client.send( lookup) # The client will also return the suggestions directly print() print('*** Result with some filters ***') for suggestion in suggestions: print suggestion.street_line, suggestion.city, ",", suggestion.state
def address_auto_complete(): auth_id = os.environ.get('smartystreets_id') auth_token = os.environ.get('smartystreets_token') credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_us_autocomplete_api_client() if not request.args: return jsonify({'msg': 'Missing address'}), 400 address = request.args.get('address') if not address: return jsonify({'msg': 'Missing address'}), 400 lookup = AutocompleteLookup(address) client.send(lookup) return jsonify( {'suggestions': [suggestion.text for suggestion in lookup.result]}), 200
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_international_street_api_client() lookup = Lookup("Rua Padre Antonio D'Angelo 121 Casa Verde, Sao Paulo", 'Brazil') lookup.geocode = True # Must be expressly set to get latitude and longitude. candidates = client.send(lookup) # The candidates are also stored in the lookup's 'result' field. first_candidate = candidates[0] print("Address is {}".format(first_candidate.analysis.verification_status)) print("Address precision: {}\n".format(first_candidate.analysis.address_precision)) print(u"First Line: {}".format(first_candidate.address1)) print(u"Second Line: {}".format(first_candidate.address2)) print(u"Third Line: {}".format(first_candidate.address3)) print(u"Fourth Line: {}".format(first_candidate.address4)) print("Latitude: {}".format(first_candidate.metadata.latitude)) print("Longitude: {}".format(first_candidate.metadata.longitude))
def suggestaddress(): credentials = StaticCredentials(AUTH_ID, AUTH_TOKEN) client = ClientBuilder(credentials).build_us_autocomplete_api_client() streetName = json.loads(request.data.decode())['streetName'] print(streetName) try: lookup = AutocompleteLookup(streetName) client.send(lookup) resp = [] for suggestion in lookup.result: resp.append(suggestion.text) return Response(json.dumps(resp, default=str), status=200, content_type="text/json") except Exception as e: return Response(json.dumps([], default=str), status=200, content_type="text/json")
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_reverse_geo_api_client() # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-input-fields lookup = Lookup(40.111111, -111.111111) results = client.send(lookup) result = results[0] coordinate = result.coordinate print("Latitude: {}".format(coordinate.latitude)) print("Longitude: {}".format(coordinate.longitude)) print("Distance: {}".format(result.distance)) address = result.address print("Street: {}".format(address.street)) print("City: {}".format(address.city)) print("State Abbreviation: {}".format(address.state_abbreviation)) print("ZIP Code: {}".format(address.zipcode)) print("License: {}".format(coordinate.get_license()))
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_autocomplete_api_client() lookup = AutocompleteLookup('4770 Lincoln Ave O') client.send(lookup) print('*** Result with no filter ***') print() for suggestion in lookup.result: print(suggestion.text) # Documentation for input fields can be found at: # https://smartystreets.com/docs/us-autocomplete-api#http-request-input-fields lookup.add_city_filter('Ogden') lookup.add_state_filter('IL') lookup.add_prefer('Fallon, IL') lookup.max_suggestions = 5 lookup.geolocate_type = geolocation_type.NONE lookup.prefer_ratio = 0.333333 lookup.add_state_filter('IL') lookup.max_suggestions = 5 suggestions = client.send( lookup) # The client will also return the suggestions directly print() print('*** Result with some filters ***') for suggestion in suggestions: print(suggestion.text)
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 run(): # key = "Your SmartyStreets Key here" # hostname = "Your Hostname here" # We recommend storing your secret keys in environment variables instead---it's safer! key = os.environ['SMARTY_AUTH_WEB'] hostname = os.environ['SMARTY_WEBSITE_DOMAIN'] credentials = SharedCredentials(key, hostname) client = ClientBuilder(credentials).build_us_autocomplete_pro_api_client() lookup = AutocompleteProLookup('4770 Lincoln Ave O') client.send(lookup) print('*** Result with no filter ***') print() for suggestion in lookup.result: print suggestion.street_line, suggestion.city, ",", suggestion.state # Documentation for input fields can be found at: # https://smartystreets.com/docs/us-autocomplete-api#http-request-input-fields lookup.add_city_filter('Ogden') lookup.add_state_filter('IL') lookup.add_city_preference('Fallon') lookup.add_state_preference('IL') lookup.max_results = 5 lookup.prefer_geo = geolocation_type.NONE lookup.prefer_ratio = 100 suggestions = client.send( lookup) # The client will also return the suggestions directly print() print('*** Result with some filters ***') for suggestion in suggestions: print suggestion.street_line, suggestion.city, ",", suggestion.state
def suggest_address(self, location): client = ClientBuilder( self.__credentials).build_us_autocomplete_api_client() lookup = auto_lookup(location['address']) lookup.add_state_filter(location['state']) lookup.max_suggestions = 9 try: suggestions = client.send(lookup) return suggestions except: return ("No candidates found.")
def run(): # key = "Your SmartyStreets Key here" # hostname = "Your Hostname here" # We recommend storing your secret keys in environment variables instead---it's safer! key = os.environ['SMARTY_AUTH_WEB'] hostname = os.environ['SMARTY_WEBSITE_DOMAIN'] credentials = SharedCredentials(key, hostname) # The appropriate license values to be used for your subscriptions # can be found on the Subscriptions page of the account dashboard. # https://www.smartystreets.com/docs/cloud/licensing client = ClientBuilder(credentials).with_licenses(["international-autocomplete-cloud"])\ .build_international_autocomplete_api_client() lookup = InternationalAutocompleteLookup('Louis') lookup.country = "FRA" client.send(lookup) print('*** Result with no filter ***') print() for suggestion in lookup.result: print suggestion.street, suggestion.locality, ",", suggestion.administrative_area # Documentation for input fields can be found at: # https://smartystreets.com/docs/us-autocomplete-api#http-request-input-fields lookup.locality = "Paris" suggestions = client.send( lookup) # The client will also return the suggestions directly print() print('*** Result with some filters ***') for suggestion in suggestions: print suggestion.street, suggestion.locality, ",", suggestion.administrative_area
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 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) # The appropriate license values to be used for your subscriptions # can be found on the Subscription page of the account dashboard. # https://www.smartystreets.com/docs/cloud/licensing client = ClientBuilder(credentials).with_licenses(['international-fake'])\ .build_international_street_api_client() # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/international-street-api#http-input-fields lookup = InternationalLookup() lookup.input_id = "ID-8675309" lookup.geocode = True # Must be expressly set to get latitude and longitude. lookup.organization = "John Doe" lookup.address1 = "Rua Padre Antonio D'Angelo 121" lookup.address2 = "Casa Verde" lookup.locality = "Sao Paulo" lookup.administrative_area = "SP" lookup.country = "Brazil" lookup.postal_code = "02516-050" candidates = client.send( lookup ) # The candidates are also stored in the lookup's 'result' field. first_candidate = candidates[0] print("Address is {}".format(first_candidate.analysis.verification_status)) print("Address precision: {}\n".format( first_candidate.analysis.address_precision)) print(u"First Line: {}".format(first_candidate.address1)) print(u"Second Line: {}".format(first_candidate.address2)) print(u"Third Line: {}".format(first_candidate.address3)) print(u"Fourth Line: {}".format(first_candidate.address4)) print("Latitude: {}".format(first_candidate.metadata.latitude)) print("Longitude: {}".format(first_candidate.metadata.longitude))
def run(): auth_id = os.environ[ 'SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables 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." lookup = Lookup(text) 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 run(): auth_id = os.environ[ 'SMARTY_AUTH_ID'] # We recommend storing your keys in environment variables 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 73 Saint Pauls Pl Brooklyn ny" lookup = Lookup(text) 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 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) # The appropriate license values to be used for your subscriptions # can be found on the Subscriptions page of the account dashboard. # https://www.smartystreets.com/docs/cloud/licensing client = ClientBuilder(credentials).with_licenses( ["us-reverse-geocoding-cloud"]).build_us_reverse_geo_api_client() # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/us-reverse-geo-api#http-input-fields lookup = Lookup(40.111111, -111.111111) results = client.send(lookup) for result in results: coordinate = result.coordinate print("Latitude: {}".format(coordinate.latitude)) print("Longitude: {}".format(coordinate.longitude)) print("Distance: {}".format(result.distance)) address = result.address print("Street: {}".format(address.street)) print("City: {}".format(address.city)) print("State Abbreviation: {}".format(address.state_abbreviation)) print("ZIP Code: {}".format(address.zipcode)) print("License: {}".format(coordinate.get_license())) print()
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()
class Extraction : def __init__(self): self.vocabulary = ['zip', 'zipcode', 'address', 'lot' ,'size', 'school', 'elementary', 'middle', 'high', 'price', 'cost', 'long', 'square foot','bedroom', 'bath', 'bathroom', 'setback', 'offers', 'million', 'millions', 'mil', 'default', 'house'] auth_id = "4bb0e1a6-e627-4dcc-bf61-18e8888c6997" auth_token = "KyWfET9otO2WvqV6c9zv" credentials = StaticCredentials(auth_id, auth_token) self.client = ClientBuilder(credentials).build_us_extract_api_client() self.lookup = ExtractLookup() self.lookup.aggressive = True self.lookup.addresses_have_line_breaks = False self.lookup.addresses_per_line = 1 self.regex = re.compile(r"(\d{5}-\d{4}|\d{5})") self.onlystreet = re.compile(r"(\d+\s+[A-z]+\s+[A-z]+)") self.longest_first = sorted(self.vocabulary, key=len, reverse=True) self.p = re.compile(r'(?:{})'.format('|'.join(map(re.escape, self.longest_first)))) logging.info("Extraction initialized...") def getMatchingKeyords(self, input): f = self.p.findall(input) return f #match exact address def getMatchingAddress(self, query): self.lookup.text = query result = self.client.send(self.lookup) list_of_addresses = [] for address in result.addresses: list_of_addresses.append(address.text) matches = self.getMatchingKeyords(query) return [list_of_addresses, matches] #match only number and street def getPartialAddressMatch(self, query): partialaddress = re.findall(self.onlystreet, query) matches = self.getMatchingKeyords(query) return [partialaddress, matches] def getZipcode(self, query): matches= re.findall(self.regex, query) return matches def getPriceRange(self, query): mod = query.replace(',', '') numbers = re.findall('[0-9]+', mod) return numbers def processQuery(self, prediction, query): if prediction == 0.0: zip = self.getZipcode(query) return [prediction, zip] if prediction == 1.0: address = self.getPartialAddressMatch(query) return [prediction, address] elif prediction == 2.0: params = self.getPartialAddressMatch(query) return [prediction, params] elif prediction == 3.0: keywords = self.getMatchingKeyords(query) return [prediction, keywords] elif prediction == 4.0: keywords = self.getMatchingKeyords(query) return [prediction, keywords] elif prediction == 5.0: keywords = self.getMatchingKeyords(query) return [prediction, keywords] elif prediction == 6.0: pricerange = self.getPriceRange(query) keywords = self.getMatchingKeyords(query) return [prediction, keywords, pricerange] elif prediction == 7.0: keywords = self.getMatchingKeyords(query) return [prediction, keywords] elif prediction == 8.0: zip = self.getZipcode(query) return [prediction, zip] elif prediction == 9.0: return [prediction] else: return None