
import pandas as pd
from tqdm import tqdm
from common.db import MysqlHelper


def read_excel(path):
    result = {}
    data_list = pd.read_excel(path).values.tolist()
    for item in data_list:
        uid, level = item[0], item[6]
        result[uid] = level
    return result


def update_level(video_obj):
    for key in tqdm(video_obj):
        uid = int(key)
        level = video_obj[key]
        sql = f"""UPDATE crawler_user_v3 SET account_level = "{level}" where uid = "{uid}";"""
        # print(sql)
        MysqlHelper.update_values(
            log_type="author",
            crawler="xiaoniangao",
            sql=sql,
            env="prod",
            machine=""
        )


if __name__ == '__main__':
    excel_path = r'/Users/luojunhui/Desktop/小年糕账号筛选.xlsx'
    account_dict = read_excel(excel_path)
    update_level(account_dict)
