def classifyZipcode(location_text): classifier = recognition_heuristic.naivebayes(recognition_heuristic.getwords) classifier.setdb('test_100.db') classified_zipcode = classifier.classify(location_text) zipcode = str(classified_zipcode[0]) confidence = str(classfied_zipcode[1]) #query MYSQL database and append to python list cur = db.cursor() cur.execute("SELECT latitude,longitude FROM sqlbook.zipcounty WHERE zipcode = %s", zipcode) rows = cur.fetchall() latitude = rows[0][0] longitude = rows[0][1] likely_zipcode = {"location_text": location_text, "zipcode": zipcode, "latitude": latitude, "longitude": longitude} weather = get__weather_data.getWeather(likely_zipcode['zipcode']) likely_zipcode.update(weather) return likely_zipcode
location_text = 'Beverly Hills' classified_zipcode = classifier.classify('Beverly Hills') zipcode = str(classified_zipcode[0]) confidence = str(classfied_zipcode[1]) #query MYSQL database and append to python list db = MySQLdb('') cur = db.cursor() cur.execute("SELECT latitude,longitude FROM sqlbook.zipcounty WHERE zipcode = %s", zipcode) rows = cur.fetchall() latitude = rows[0][0] longitude = rows[0][1] likely_zipcode = {"location_text": location_text, "zipcode": zipcode, "latitude": latitude, "longitude": longitude} weather = get__weather_data.getWeather(likely_zipcode['zipcode']) likely_zipcode.update(weather) print likely_zipcode #if not close enough #select 10 close locations to the one classified. cur.execute("""SELECT z.zipcode, z.state, zco.poname, distcirc, population, hh, hhmedincome, z.latitude, z.longitude FROM (SELECT zips.*, ACOS(COS(comp.latrad)*COS(zips.latrad)* COS(comp.longrad - zips.longrad) + SIN(comp.latrad)*SIN(zips.latrad))*radius as distcirc FROM (SELECT zc.*, latitude*PI()/180 as latrad, longitude*PI()/180 as longrad, 3949.9 as radius