Exemplo n.º 1
0
 def test_dot_us_auth(self):
     """
     GeocoderDotUS Authorization header
     """
     geocoder = GeocoderDotUS(username='******', password='******')
     with patch.object(
             geocoder, '_call_geocoder',
             side_effect=NotImplementedError()) as mock_call_geocoder:
         with self.assertRaises(NotImplementedError):
             geocoder.geocode("1 5th Ave NYC")
         args, kwargs = mock_call_geocoder.call_args
         request = args[0]
         self.assertEqual(request.get_header('Authorization'),
                          'Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
Exemplo n.º 2
0
def geocoderdotus(query):
    us = GeocoderDotUS()
    try:
        place, (lat, lng) = us.geocode(query)
        return (lat, lng)
    except:
        return None, None
Exemplo n.º 3
0
def get_lat_long(city, state, address):

	from geopy.geocoders import GeocoderDotUS
	f_string = "%s {0} {1}".format(city, state)
	geolocator = GeocoderDotUS(format_string=f_string)
	address, (latitude, longitude) = geolocator.geocode(address)
	return (address, latitude, longitude)
Exemplo n.º 4
0
    def test_dot_us_auth(self):
        """
        GeocoderDotUS Authorization header
        """
        geocoder = GeocoderDotUS(username='******', password='******')

        def _print_call_geocoder(query, timeout, raw):
            """
            We want to abort at call time and just get the request object.
            """
            raise Exception(query)

        geocoder._call_geocoder = _print_call_geocoder
        exc_raised = False
        try:
            geocoder.geocode("1 5th Ave NYC")
        except Exception as err:
            exc_raised = True
            request = err.message if not py3k else err.args[0]
            self.assertEqual(request.get_header('Authorization'),
                             'Basic dXNlcm5hbWU6cGFzc3dvcmQ=')
        self.assertTrue(exc_raised)
Exemplo n.º 5
0
Arquivo: dotus.py Projeto: 0x836/geopy
    def test_dot_us_auth(self):
        """
        GeocoderDotUS Authorization header
        """
        geocoder = GeocoderDotUS(username='******', password='******')

        def _print_call_geocoder(query, timeout, raw):
            """
            We want to abort at call time and just get the request object.
            """
            raise Exception(query)

        geocoder._call_geocoder = _print_call_geocoder
        exc_raised = False
        try:
            geocoder.geocode("1 5th Ave NYC")
        except Exception as err:
            exc_raised = True
            request = err.message if not py3k else err.args[0]
            self.assertEqual(
                request.get_header('Authorization'),
                'Basic dXNlcm5hbWU6cGFzc3dvcmQ='
            )
        self.assertTrue(exc_raised)
Exemplo n.º 6
0
##########################################################################

FEATURES = ["Address", "Latitude", "Longitude"]

##########################################################################
## Program converts addresses to latitude and longitude (Starbucks, McDonald's) to CSV file.
##########################################################################
if __name__== "__main__":
	#Import the data frame
	df = pd.read_excel(DATAPATH,header=None, names=FEATURES)
	
	
	#Loop through addresses for each coordinate
	geolocator = GeocoderDotUS(format_string="%s, Washington DC")
	for row in range (0,48):
		address, coordinates = geolocator.geocode(df["Address"][row])
		df.loc[row, "Address"] = address
		df.loc[row, "Latitude"] = coordinates[0]
		df.loc[row, "Longitude"] = coordinates[1]
		
	
	#Write the results to a CSV file
	df.to_csv(OUTPATH, index=False)