Example #1
0
def geocode_zip(zipcode):
    """ Get zipcode geocoding information """
    try:
        geocode = GoogleGeocode(zipcode)
        return geocode.google_maps_api()
    except:
        return {'error': 'Error while getting geocoding information for ' + zipcode}
Example #2
0
    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 = GoogleGeocode(obj.zipcd[:5])
                geocode_data = geocode.google_maps_api()
                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)