auto_commnet.py 1.89 KB
import requests
import time
import datetime
import pymysql
import random
import traceback
import logging
from auto_request import login, time_convs, reply, get_comment
from auto_request import host, user, port, db, passwd



def get_topic_id(numtime):
    try:
        pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=port)
        cursor = pc.cursor()
        cursor.execute(
            "SELECT user_id,id   FROM topic WHERE is_online=1 and create_time LIKE '%%%%%s%%%%' and user_id in (select user_id from user_extra  where is_shadow = 0) " % numtime)
        data = cursor.fetchall()
        topic_id = list(data)
        logging.info("Database version : %s " % topic_id)
        pc.close()
        return topic_id
    except:
        logging.error("catch exception,get_data:%s" % traceback.format_exc())
        return None


if __name__ == "__main__":

    try:

        time_list = [1, 2, 3, 4, 5, 6, 7]

        for i in time_list:

            numtime = time_convs(i)

            topic_id = get_topic_id(numtime)

            dicts = {}

            for i in topic_id:

                if i[0] not in dicts.keys():
                    dicts.setdefault(i[0], [])
                    dicts[i[0]].append(i[1])

                else:
                    dicts[i[0]].append(i[1])

            comment = get_comment()

            for key, value in dicts.items():

                rand_num = random.randint(0, len(value) - 1)

                rand_id = value[rand_num]

                for i in range(1):

                    time.sleep(random.randint(10, 20))

                    cook = login()

                    if cook is not None:

                        reply(cook, id, comment)

    except:

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


#. 每日一次轮询,昨、2、3、4、5、6、7日新增帖的用户:随机从马甲库里取一个马甲,搭配随机评论库一条评论。每天每人最多一个帖子被评论。