import pymysql
import traceback
import logging
from auto_request import host, user, db, passwd
from log_settings import *


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):
                    print(user_id)
                    user_id_list.append(user_id[0])
        else:
            pass
        pc.close()
        return user_id_list
    except:
        logging.error("catch exception,get_data:%s" % traceback.format_exc())
        return None


data = get_data()
print(data)
file = open("/data/log/cybertron/app/user_id.txt", "w")

if data:
    for i in data:
        file.write(str(i[0]))
        file.write("\n")