fix_no_comment_click.py 1.38 KB
import pymysql
import traceback
import logging
from vest.request.auto_request import login, time_convs, reply, get_comment, click
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception


def get_topic_id(numtime1, numtime2):
    try:
        pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
        cursor = pc.cursor()
        cursor.execute(
            "SELECT id,user_id   FROM topic WHERE is_online=1 and create_time >  '%s' and create_time < '%s' and id not in "
            "(select topic_id from reply where  create_time >  '%s' and create_time < '%s')" % (
                numtime1, numtime2, numtime1, numtime2)
        )
        data = cursor.fetchall()
        topic_id = list(data)
        logging.info("Database version : %s " % topic_id)

        return topic_id

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


def fix_no_comment_click():
    try:
        numtime1, numtime2 = time_convs(8, 0)
        user_id = get_topic_id(numtime1, numtime2)
        for i in user_id:
            cook = login()
            if cook is not None:
                click(cook, i[0])
                comment = get_comment()
                reply(cook, i[0], comment)

    except:
        logging_exception()
        logging.error("catch exception,main :%s" % traceback.format_exc())