Пример #1
0
def main():
    trainSet = loadData()
    mysql = MySql('locations', 'leo', 'mm123456', collection='new_provices')
    cursor = connect('lagou', 'predicts')
    results = mysql.find()

    for result in results:
        province = result.get('Province')
        city = result.get('city')
        county = result.get('county')
        lng = float(result.get('Longitude'))
        lat = float(result.get('latitude'))
        neighbors = get_neighbors(trainSet, [lng, lat], 1)
        assume = predict(neighbors)
        cursor.insert({
            'province': province,
            'city': city,
            'county': county,
            'lng': lng,
            'lat': lat,
            'value': assume
        })

    mysql.close()
Пример #2
0
from utils.mongo import connect
from utils.mysql import MySql

mysql = MySql('locations', 'leo', 'mm123456', collection='new_provices')
locations = connect('lagou', 'location')

cities = []
try:
    for location in locations.find():
        city = location.get('city')
        new_city = city + '%'
        result = mysql.find(mohu=True, city=new_city)
        try:
            province = result.get('Province')
        except Exception:
            print(city)
        locations.update_one({'city': city}, {'$set': {'province': province}})
finally:
    mysql.close()