Пример #1
0
    def run(self):
        status = self.pre_check()
        if not status:
            return

        Log.v("正在查询车次余票信息")
        count = 1

        while True:
            self.maintain_mode()
            self.heart_beat_mode()
            dates = DispatcherTool.query_travel_dates
            if Config.basic_config.use_station_group:
                station_groups = [(v.from_station, v.to_station)
                                  for v in Config.basic_config.station_groups]
            else:
                station_groups = list(
                    product(Config.basic_config.from_stations,
                            Config.basic_config.to_stations))
            query_params = list(product(dates, station_groups))

            for query_params in query_params:
                Log.v("查询第 {0} 次".format(count))
                n = datetime.datetime.now()
                data = DispatcherTool.run(query_params)
                count += 1
                self.submit_order(data)
                DispatcherTool.output_delta_time(n)
                if self.order_id or self.unfinished_order:
                    break
            if self.order_id or self.unfinished_order:
                break
        self.notice_user()
 def batch_tasks(self, query_data):
     n = datetime.datetime.now()
     data = DispatcherTool.run(query_data)
     DispatcherTool.output_delta_time(n)
     self.submit_order(data)
     if self.order_id:
         self.pool.close()
Пример #3
0
    def run(self):
        if not self.login():
            return
        p_status = self.query_passengers()
        if not p_status:
            return
        if not Config.auto_code_enable:
            Log.v("未开启自动打码功能, 不检测用户登录状态")
        Log.v("正在查询车次余票信息")

        count = 0

        while True:
            if self.check_maintain():
                Log.v("12306系统每天 23:00 - 6:00 之间 维护中, 程序暂时停止运行")
                maintain_time = self.delta_maintain_time()
                Log.v("{0}小时 {1}分钟 {2}秒之后重新启动".format(
                    maintain_time.seconds // 3600,
                    (maintain_time.seconds // 60) % 60,
                    maintain_time.seconds % 3600 % 60))
                time.sleep(self.delta_maintain_time().total_seconds())
            if Config.auto_code_enable:
                status, msg = self.online_checker()
                Log.v(msg)
                if not status:
                    Log.e("心跳登录失败,继续重试中,建议手动检查原因再尝试重启")
                    self.online_checker_now()

            dates = DispatcherTool.query_travel_dates
            for query_date in dates:
                Log.v("查询第 {0} 次".format(count))
                n = datetime.datetime.now()
                data = DispatcherTool.run(query_date)
                count += 1
                self.submit_order(data)
                DispatcherTool.output_delta_time(n)
                if self.order_id or self.unfinished_order:
                    break
            if self.order_id or self.unfinished_order:
                break

        if self.order_id:
            Log.v(
                "抢票成功,{notice}".format(notice="你已开启邮箱配置,稍后会收到邮件通知" if Config.
                                       email_notice_enable else "如需邮件通知请先配置"))
            Log.v("车票信息:")
            for order_ticket in self.order_tickets:
                print(order_ticket)

            # 抢票成功发邮件信息
            send_email(
                2, **{
                    "order_no":
                    self.order_id,
                    "ticket_info":
                    "</br>".join([v.to_html() for v in self.order_tickets])
                })
        else:
            Log.v("您有未完成订单, 请及时处理后再运行程序")
            send_email(3)