
import pymysql
import pandas as pd
DIRECTORY_PATH = '/data2/models/'

def get_video_id():
    db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle')
    cursor = db.cursor()
    sql = "select diary_id from feed_diary_boost;"
    cursor.execute(sql)
    result = cursor.fetchall()
    df=pd.DataFrame(list(result))
    df.to_csv('/data2/models/video_diary_id.csv',index=None)
    print("成功")
    db.close()

def queue():
    db = pymysql.connect(host='rm-m5e842126ng59jrv6.mysql.rds.aliyuncs.com', port=3306, user='doris',
                         passwd='o5gbA27hXHHm', db='doris_prod')
    cursor = db.cursor()
    sql = "select native_queue from device_diary_queue where device_id = 'AB20292B-5D15-4C44-9429-1C2FF5ED26F6';"
    cursor.execute(sql)
    result = cursor.fetchall()
    df = pd.DataFrame(list(result))
    all = df.loc[0,0].split(",")
    print(all[:10])
    db.close()
    return all

def get_local_device():
    db = pymysql.connect(host='192.168.15.12', port=4000, user='root', db='jerry_test')
    cursor = db.cursor()
    sql = "select device_id,city_id from user_active_time"
    cursor.execute(sql)
    result = cursor.fetchall()
    df = pd.DataFrame(list(result)).dropna()
    df = df.rename(columns={"0": "device_id", "1": "city_id"})
    db.close()
    df.to_csv('/Users/mac/utils/test_device_city_id.csv', index=None)
    print(1)

if __name__=="__main__":
    LOCAL_HOST = 'rdsmaqevmuzj6jy.mysql.rds.aliyuncs.com'
    db = pymysql.connect(host=LOCAL_HOST, port=3306, user='work', passwd='workwork', db='doris_test')
    diary_id = [14207355,16197023,13006945,12363565,15296547,15082216,16198052,15228350,13006942,14229868,15303563,16211116,15225921,15250715,15271108,15479315,16197047,15544727,15336944,15486003,15517196,16211130,15547275,15572010]
    device_id = '99000645287876'
    city_id = 'beijing'
    cursor = db.cursor()
    id_str = str(diary_id[0])
    for i in range(1, len(diary_id)):
        id_str = id_str + "," + str(diary_id[i])

    sql = "insert into device_diary_queue values ('{}','{}','{}','{}','{}','{}',89)".format \
        (device_id, city_id,id_str,id_str,id_str,id_str)
    cursor.execute(sql)
    db.commit()
    db.close()
    print("成功写入diary_id")




