def geocode_zip(zipcode): """ Get zipcode geocoding information """ try: return geocode_get_data(zipcode) except: return {'error': 'Error while getting geocoding information for ' + zipcode}
def test_geocode_get_data__new(self, mock_geocode): """Testing geocode_get_data, with new argument.""" mock_geocode.return_value = {'result': ['20005', 11, 22]} result = geocode_get_data('DEFINITELY-NOT_CACHED') self.assertTrue('zip' in result) self.assertEqual(result['zip']['zipcode'], '20005') self.assertEqual(result['zip']['lat'], 11) self.assertEqual(result['zip']['lng'], 22)
def test_geocode_get_data__new(self, mock_geocode): """Testing geocode_get_data, with new argument.""" mock_geocode.return_value = {"result": ["20005", 11, 22]} result = geocode_get_data("DEFINITELY-NOT_CACHED") self.assertTrue("zip" in result) self.assertEqual(result["zip"]["zipcode"], "20005") self.assertEqual(result["zip"]["lat"], 11) self.assertEqual(result["zip"]["lng"], 22)
def geocode_zip(zipcode): """ Get zipcode geocoding information """ try: return geocode_get_data(zipcode) except: return { 'error': 'Error while getting geocoding information for ' + zipcode }
def test_geocode_get_data__expired(self, mock_geocode): """Testing geocode_get_data, with empty argument.""" mock_geocode.return_value = {"result": ["20006", 11, 22]} cg = CachedGeodata(key="20006", lat=111, lon=222, expires=time.time() - 10000) cg.save() result = geocode_get_data("20006") self.assertEqual(result["zip"]["zipcode"], "20006") self.assertEqual(result["zip"]["lat"], 11) self.assertEqual(result["zip"]["lng"], 22)
def test_geocode_get_data__existent(self): """Testing geocode_get_data, with cached argument.""" cg = CachedGeodata(key="20005", lat=111, lon=222, expires=time.time() + 10000) cg.save() result = geocode_get_data("20005") self.assertTrue("zip" in result) self.assertEqual(result["zip"]["zipcode"], "20005") self.assertEqual(result["zip"]["lat"], 111) self.assertEqual(result["zip"]["lng"], 222)
def test_geocode_get_data__existent(self): """Testing geocode_get_data, with cached argument.""" cg = CachedGeodata(key='20005', lat=111, lon=222, expires=time.time() + 10000) cg.save() result = geocode_get_data('20005') self.assertTrue('zip' in result) self.assertEqual(result['zip']['zipcode'], '20005') self.assertEqual(result['zip']['lat'], 111) self.assertEqual(result['zip']['lng'], 222)
def test_geocode_get_data__expired(self, mock_geocode): """Testing geocode_get_data, with empty argument.""" mock_geocode.return_value = {'result': ['20006', 11, 22]} cg = CachedGeodata(key='20006', lat=111, lon=222, expires=time.time() - 10000) cg.save() result = geocode_get_data('20006') self.assertEqual(result['zip']['zipcode'], '20006') self.assertEqual(result['zip']['lat'], 11) self.assertEqual(result['zip']['lng'], 22)
def insert_counselor(self, counselor): """ Save a counseling agency to local database """ if not counselor or counselor == {}: return self.sanitize_values(counselor) obj = CounselingAgency() obj.agcid = counselor.get('agcid', '') obj.adr1 = counselor.get('adr1', '') obj.adr2 = counselor.get('adr2', '') obj.city = counselor.get('city', '') obj.email = counselor.get('email', '') obj.fax = counselor.get('fax', '') obj.nme = counselor.get('nme', '') obj.phone1 = counselor.get('phone1', '') obj.statecd = counselor.get('statecd', '') obj.weburl = counselor.get('weburl', '') obj.zipcd = counselor.get('zipcd', '') obj.agc_ADDR_LATITUDE = counselor.get('agc_ADDR_LATITUDE', '') obj.agc_ADDR_LONGITUDE = counselor.get('agc_ADDR_LONGITUDE', '') obj.languages = counselor.get('languages', '') obj.services = counselor.get('services', '') obj.parentid = counselor.get('parentid', '') obj.county_NME = counselor.get('county_NME', '') obj.phone2 = counselor.get('phone2', '') obj.mailingadr1 = counselor.get('mailingadr1', '') obj.mailingadr2 = counselor.get('mailingadr2', '') obj.mailingcity = counselor.get('mailingcity', '') obj.mailingzipcd = counselor.get('mailingzipcd', '') obj.mailingstatecd = counselor.get('mailingstatecd', '') obj.state_NME = counselor.get('state_NME', '') obj.state_FIPS_CODE = counselor.get('state_FIPS_CODE', '') obj.faithbased = counselor.get('faithbased', '') obj.colonias_IND = counselor.get('colonias_IND', '') obj.migrantwkrs_IND = counselor.get('migrantwkrs_IND', '') obj.agc_STATUS = counselor.get('agc_STATUS', '') obj.agc_SRC_CD = counselor.get('agc_SRC_CD', '') obj.counslg_METHOD = counselor.get('counslg_METHOD', '') try: if obj.agc_ADDR_LATITUDE == '0' or obj.agc_ADDR_LONGITUDE == '0': geocode_data = geocode_get_data(obj.zipcd[:5]) if 'zip' in geocode_data: obj.agc_ADDR_LATITUDE = geocode_data['zip']['lat'] obj.agc_ADDR_LONGITUDE = geocode_data['zip']['lng'] else: raise Exception('Could not obtain geocoding information for zipcode [%s]' % obj.zipcd) obj.save() except Exception as e: self.errors += 'Error while saving agency [%s]: %s\n' % (obj.nme, e)
def geocode_zip(zipcode): """ Get zipcode geocoding information """ #try: return geocode_get_data(zipcode, zip_only=True)