auto_user_id.py 1.47 KB
import pymysql
import traceback
import logging
import json
from vest.request.auto_request import host, user, db, passwd
from libs.cache import redis_client
from libs.error import logging_exception


def get_data():
    try:
        pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
        cursor = pc.cursor()
        cursor.execute("select user_id from user_extra  where is_shadow = 1 ")
        data = cursor.fetchall()
        user_id = list(data)
        logging.info("Database version : %s " % user_id)
        user_id_list = []
        if user_id:
            for i in user_id:
                cursor.execute("select  user_id from topic  where user_id = " + str(
                    i[0]) + " group by user_id  having count(user_id) >5")
                data = cursor.fetchall()
                user_id = list(data)
                if len(user_id):
                    user_id_list.append(user_id[0])
        pc.close()
        return user_id_list
    except:
        logging.error("catch exception,get_data:%s" % traceback.format_exc())
        return None


def auto_user_id():
    try:
        data = get_data()
        file = open("/srv/apps/physical/vest/data/get_user_id.txt", "w")
        if data:
            for i in data:
                file.write(str(i[0]))
                file.write("\n")
        redis_client.set("get_user_id_data", json.dumps(data))

    except:
        logging_exception()
        logging.error("index_first:%s" % traceback.format_exc())