Beispiel #1
0
    def reserve_and_seckill(self, work_count=5):
        """
        预约并抢购
        """
        user_run_once = self.run_once
        while True:
            self.run_once = True

            # 每天抢购结束后,需要重新获取新的时间点
            logger.info("重新获取秒杀开始时间...")
            self.timers = Timer()

            logger.info("开始预约")
            try:
                self.make_reserve()
            except Exception as e:
                logger.info('预约发生异常!', e)

            logger.info("等待验证Cookie是否已经过期")
            if self.timers.need_relogin():
                self.validate_cookie()

            logger.info("等待进入秒杀")
            with ProcessPoolExecutor(work_count) as pool:
                for i in range(work_count):
                    pool.submit(self._seckill)
            logger.info("本次抢购进程全部结束并退出")

            if user_run_once:
                logger.info("用户设定只运行一次,退出循环...")
                break
            else:
                wait_some_time()
    def __init__(self):
        self.spider_session = SpiderSession()
        self.spider_session.load_cookies_from_local()

        self.qrlogin = QrLogin(self.spider_session)

        # 初始化信息
        self.sku_id = global_config.getRaw('config', 'sku_id')
        self.seckill_num = global_config.getRaw('config', 'seckill_num')
        self.seckill_init_info = dict()
        self.seckill_url = dict()
        self.seckill_order_data = dict()
        self.timers = Timer()

        self.session = self.spider_session.get_session()
        self.user_agent = self.spider_session.user_agent
        self.nick_name = None
Beispiel #3
0
    def __init__(self):
        self.spider_session = SpiderSession()
        self.spider_session.load_cookies_from_local()

        self.qrlogin = QrLogin(self.spider_session)

        # 初始化信息
        self.sku_id = global_config.getRaw('config', 'sku_id')
        self.seckill_num = global_config.getRaw('config', 'seckill_num')
        self.seckill_init_info = dict()
        self.seckill_url = dict()
        self.seckill_order_data = dict()
        self.timers = Timer()

        self.session = self.spider_session.get_session()
        self.user_agent = self.spider_session.user_agent
        self.nick_name = None

        logger.info('商品名称:{}'.format(self.get_sku_title()))
        logger.info('商品url:{}'.format('https://item.jd.com/{}.html'.format(
            self.sku_id)))
Beispiel #4
0
from maotai.timer import Timer

timer = Timer()
print(timer.jd_time())