def getLatLong(self, locAddress): try: g = geocoder.tamu(locAddress.get('address1'), city=locAddress.get('city'), state=locAddress.get('state'), zipcode=locAddress.get('zip'), key=self.key) if (g.json.get('accuracy') == 'GPS' or g.json.get('accuracy') == 'BuildingCentroid' or g.json.get('accuracy') == 'Parcel' or g.json.get('accuracy') == 'StreetSegment' or g.json.get('accuracy') == 'StreetIntersection' or g.json.get('accuracy') == 'StreetCentroid'): f = {} f['latitude'] = g.json.get('output_geocode').get('Latitude') f['longitude'] = g.json.get('output_geocode').get('Longitude') f['accuracy'] = g.json.get('accuracy') f['error'] = 'true' return f else: f = {} f['latitude'] = g.json.get('output_geocode').get('Latitude') f['longitude'] = g.json.get('output_geocode').get('Longitude') f['accuracy'] = g.json.get('accuracy') f['error'] = 'false' return f except Exception as e: print("*********************************************") print(e) print("*********************************************") return dict()
def test_tamu(): g = geocoder.tamu( us_address, city=us_city, state=us_state, zipcode=us_zipcode) assert g.ok
def test_tamu(): g = geocoder.tamu(location, city='San Francisco', state='CA', zipcode='94105') assert g.ok osm_count, fields_count = g.debug()[0] assert osm_count == 5 assert fields_count == 28
def test_tamu(): g = geocoder.tamu( location, city='San Francisco', state='CA', zipcode='94105') assert g.ok osm_count, fields_count = g.debug()[0] assert osm_count == 5 assert fields_count == 28
def GeoCoder(df): with req.Session() as session: # iterate through row, extract parts of address to variables, then construct the json, execute the geocoder.json request, handle the return file, NEXT # for index, row in df.iterrows(): geocoded = False while geocoded is not True: try: # this is a good place to use the session.get() method # the geocode_results should be the result of the get method output = [ 'location={loc}, city={c}, state={s}, zipcode={z}, key={k}' .format(loc=df["Address"], c=df["City"], s=df["State"], z=df["ZipCode"], dict_keys=df["key"]) ] geocode_results = geocoder.tamu( output ) #This is the failure point in Jupyter, I've tried dicts, formatted strings, lists but so far haven't made it work geocode_results.json #TODO: insert only lat/lon back into df except Exception as e: logger.exception(e) geocoded = True # check results if geocode_results[ 'status'] == 'OVER_QUERY_LIMIT': # TODO: OVER LIMIT, EXCEEDED BANDWIDTH, 404, etc., may want to add more error conditions depending on real life lessons logger.info("Hit our limit!") geocoded = False else: # If all goes well, we want to save the results if geocode_results['status'] != 'OK': logger.warning("Error geocoding {}: {}".format( address, geocode_results['status'])) logger.debug("Geocoded {}: {}".format( address, geocode_results['status'])) results.append(geocode_results) geocoded = True return df