python-活动秒杀模板

python-活动秒杀模板源码

#-*- coding = utf-8 -*-
#Time : 2021/1/13 
#Author : 小柠檬
#File : 秒杀模板.py
import gevent.pool
import gevent.monkey
gevent.monkey.patch_all()
import requests
import json
import time
import threading

def lottery(a):
    url = 'https://iosapi.peiyinxiu.com/Api/User/OpenTask?addGold=1500&appkey=8b232b5997100d5a&taskId=20&token=8ce65ae7b582e0c0051125c0fd30da23&type=0&userId=164046973&sign=b9ee037c1ac5db2860999025683ca754'
    headers = {
     'User-Agent': 'dubbingshow/9.20.974/84c1be1a9909602db6746f02fd851d92(iPhone 6s;iOS13.1.2;750*1334)/164046388'}
    cookies = {
     'Cookie': 'Hm_lvt_0ce3585f47fda4b00bdda05866a55839=1610022693,1610023112,1610037170,1610037185'}

    try:
        r = requests.post(url, headers=headers,cookies=cookies)
        print(r.text)

    except Exception as e:
        print(e)

def geventMain(coroutinesNum):
    pool = gevent.pool.Pool()
    pool.map(lottery, (i for i in range(coroutinesNum)))

def threadMain(coroutinesNum):
    t = threading.Thread(target=geventMain,args=(coroutinesNum,))
    t.start()

if __name__ == '__main__':
    coroutinesNum = int(input('请输入协程数:'))
    count = int(input('请输入循环轮数:'))
    delay = float(input('请输入循环延迟(秒):'))
    times = input('请输入定时时间(00:00:00):')

    print('-'*10,'详细信息','-'*10)
    print('协程数:',coroutinesNum)
    print('循环轮数:',count)
    print('延迟(秒):',delay)
    print('定时时间:',times)
    print('-' * 10, '详细信息', '-' * 10)

    while True:
        print('\r',time.strftime('%H:%M:%S'),end='')
        if time.strftime('%H:%M:%S') == times:
            print()
            for i in range(count):
                threadMain(coroutinesNum)
                time.sleep(delay)

            break

        time.sleep(0.3)

    time.sleep(60)
    print('抽奖完成!')
    input('按下回车结束程序...')

你可能感兴趣的:(python-活动秒杀模板,python)