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) pc.close() return user_id except: logging.error("catch exception,get_data:%s" % traceback.format_exc()) return None data = get_data() file = open("user_id.txt","w") for i in data: file.write(i[0]) file.write("\n")