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()
    df = pd.DataFrame(list(result))
    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')
    # List("AB20292B-5D15-4C44-9429-1C2FF5ED26F6", "802C5FDC-5DC6-42D0-8F6F-2DBE200BB21B",
    #      "358035085192742", "B2F0665E-4375-4169-8FE3-8A26A1CFE248", "863455037703008",
    #      "65EC6C14-1AD6-44C2-AED2-C41452284E91", "29548727-8242-4D58-8151-F603F975BB98")
    # sql_delete = ""
    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()



