import pymysql
import pandas as pd


def get_data():
    db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle')
    cursor = db.cursor()
    sql = "select native_queue,nearby_queue,nation_queue,megacity_queue,device_id,city_id from ffm_diary_queue;"
    cursor.execute(sql)
    result = cursor.fetchall()
    pd.DataFrame(list(result)).to_csv("/home/gmuser/ffm.csv", index=None)
    df = pd.read_csv("/home/gmuser/ffm.csv")
    for i in range(df.shape[0]):
        a = df.loc[i, :].values
        insert(a)


def insert(a):
    db = pymysql.connect(host='rm-m5e842126ng59jrv6.mysql.rds.aliyuncs.com', port=3306, user='doris',
                         passwd='o5gbA27hXHHm',
                         db='doris_prod')
    sql = "INSERT INTO device_diary_queue (native_queue, nearby_queue, nation_queue, " \
          "megacity_queue,device_id,city_id) VALUES ('{}','{}','{}','{}','{}','{}');".format \
        (a[0], a[1], a[2],a[3],a[4], a[5])
    cursor = db.cursor()
    cursor.execute(sql)
    db.commit()
    db.close()
    print("end")


if __name__ == "__main__":
    get_data()



