true_click_one.py 1.82 KB
import pymysql
import traceback
import logging
from vest.request.auto_request import login, click, time_conv
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception


def get_data(numtime, numtime2):
    try:
        pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
        cursor = pc.cursor()
        logging.info("get numtime:%s" % numtime)
        logging.info("get numtime2:%s" % numtime2)
        cursor.execute(
            "SELECT  user_id,id FROM topic WHERE is_online=1  and (create_time >= '%s' and create_time <= '%s')" % (
                numtime, numtime2))
        data = cursor.fetchall()
        topic_id = list(data)
        topic_id_list = []
        logging.info("get topic_id:%s" % topic_id)
        for i in topic_id and topic_id:
            cursor.execute(
                "select user_id,is_shadow from user_extra where user_id =" + str(
                    i[0]) + " and is_online =1 and  is_deleted =0")
            data = cursor.fetchall()
            user_id = list(data)
            logging.info("get user_id:%s" % user_id)
            if (user_id and user_id[0][1] == 0) or len(user_id) == 0:
                topic_id_list.append(i)
        logging.info("Database version : %s " % topic_id_list)
        pc.close()

        return topic_id_list

    except:
        logging.error("catch exception,get_data:%s" % traceback.format_exc())
        return []


def true_click_one():
    try:
        numtime, numtime2 = time_conv(5, 0)
        user_id = get_data(numtime, numtime2)
        for i in user_id:
            cook = login()
            logging.info("get cook:%s" % cook)
            if cook is not None:
                click(cook, i[1])
    except:
        logging_exception()
        logging.error("catch exception,main:%s" % traceback.format_exc())