auto_star_urge.py 1.45 KB
import requests
import time
import datetime
import pymysql
import random
import pandas as pd
import traceback
from log_settings import *
import logging
from auto_request import login, time_conv, Urge
from auto_request import host, user, port, db, passwd



def get_star_useid(numtime):

    try:
        pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=port)
        cursor = pc.cursor()
        cursor.execute(
            "SELECT distinct(user_id) FROM topic WHERE is_online=1 and  (content_level =4 or content_level =5) and create_time LIKE '%%%%%s%%%%' and user_id in (select user_id from user_extra  where is_shadow = 0)" % numtime)
        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


if __name__ == "__main__":

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

        for i in time_list:

            numtime = time_conv(i)

            user_id = get_star_useid(numtime)

            for j in user_id:

                id = int(j[0])

                for i in range(1):

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

                    cookies = login()

                    if cookies is not None:

                        Urge(cookies, id)

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