Example #1
0
    def loopQuery(trainDate, fromStation, toStation, passengerType=PASSENGER_TYPE_ADULT, trainsNo=[],
                  seatTypes=[SEAT_TYPE[key] for key in SEAT_TYPE], PASSENGERS_ID=[], POLICY_BILL=1,
                  timeInterval=QUERY_TICKET_REFERSH_INTERVAL,heart_beat_request_time = 3):
        count = 0
        base_query_url = queryUrls['query']['url']
        while True:
            nowTime, status = deadline.do_fix_time()
            if status:
                Log.v('当前时间:%s 处于23点到6点之间,12306处于维护状态,暂不处理下单业务' % nowTime)
                continue

            count += 1
            #标记是否登录已失效,heart_beat_request_time次发送一次心跳
            flag = True
            if count % heart_beat_request_time == 0:
                status = check_re_login()
                if not status:
                    flag = False
            Log.v('正在为您第%d次刷票' % count + ',当前时间为:%s' % datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
            for ticketDetails in Query.querySpec(count, base_query_url, trainDate, fromStation, toStation,
                                                 passengerType, trainsNo, seatTypes,
                                                 PASSENGERS_ID, POLICY_BILL):
                if ticketDetails:
                    return flag,ticketDetails
            time.sleep(timeInterval)
Example #2
0
def girl_of_the_night(love):
    Log.v('启动***休眠监控***线程')
    count = 0
    while 1:
        if love.get_my_love():
            break
        now = datetime.datetime.now()
        nowHour = now.hour
        if nowHour >= 23 or nowHour < 6:
            if count % HEART_BEAT_PER_REQUEST_TIME == 0:
                check_re_login()
            time.sleep(HEART_BEAT_PER_REQUEST_TIME >> 1)
            count += 1
            continue
        # Log.e('非23点-6点,休眠%s秒'%(HEART_BEAT_PER_REQUEST_TIME << 1))
        time.sleep(HEART_BEAT_PER_REQUEST_TIME << 1)
Example #3
0
def girl_of_the_night(love):
    Log.v('启动***休眠监控***线程')
    while 1:
        if love.get_my_love():
            break
        if love.get_login_status():
            status = check_re_login()
            if status:
                EasyHttp.save_cookies(COOKIE_SAVE_ADDRESS)
        time.sleep(HEART_BEAT_PER_REQUEST_TIME)

    Log.v('****** 12306 终止 ******')
Example #4
0
def girl_of_the_night(love):
    Log.v('启动***休眠监控***线程')
    count = 0
    while 1:
        if love.get_my_love():
            break
        now = datetime.datetime.now()
        nowHour = now.hour
        if nowHour >= 23 or nowHour < 6:
            if count % HEART_BEAT_PER_REQUEST_TIME == 0:
                status = check_re_login()
                if status:
                    EasyHttp.save_cookies(COOKIE_SAVE_ADDRESS)
            time.sleep(HEART_BEAT_PER_REQUEST_TIME >> 1)
            count +=1
            continue
        # Log.e('非23点-6点,休眠%s秒'%(HEART_BEAT_PER_REQUEST_TIME << 1))
        time.sleep(HEART_BEAT_PER_REQUEST_TIME << 1)
Example #5
0
def super_hero(love):
    Log.v('启动***超级英雄***线程')
    #免费代理ip访问
    GetFreeProxy.getAllProxy(THREAD_POOL_SIZE, THREAD_OR_PROCESS, IS_REFASH_IP_POOL)
    init_ip_pool()

    EasyHttp.load_cookies(COOKIE_SAVE_ADDRESS)
    cookies = {c.name: c.value for c in EasyHttp.get_session().cookies}

    RAIL_EXPIRATION = cookies.get('RAIL_EXPIRATION')
    #(int(RAIL_EXPIRATION)-172800000) < int(time.time()*1000)
    if RAIL_EXPIRATION and int(RAIL_EXPIRATION) < int(time.time()*1000) :
        Log.d('cookie登录已过期,重新请求')
        status,login = do_login()
        if not status:
            love.change_offline_status(True)
            return
    else:
        if not ('uamtk' in cookies and 'RAIL_DEVICEID' in cookies):
            status,login = do_login()
            if not status:
                love.change_offline_status(True)
                return
        else:
            status = check_login()
            if not status:
                love.change_offline_status(True)
                return
            login = Login()
            login._urlInfo = loginUrls['normal']
            Log.v('已登录状态,开始寻找小票票')

    love.change_login_status(True)
    seatTypesCode = SEAT_TYPE_CODE if SEAT_TYPE_CODE else [SEAT_TYPE[key] for key in SEAT_TYPE.keys()]
    passengerTypeCode = PASSENGER_TYPE_CODE if PASSENGER_TYPE_CODE else '1'
    Log.d("订单详情:日期[%s]/区间[%s至%s]%s/车次[%s]/刷票间隔[%ss]"%(TRAIN_DATE,FROM_STATION,TO_STATION,'/出发时间段['+'~'.join(leave_time)+']' if leave_time else '',','.join(TRAINS_NO),QUERY_TICKET_REFERSH_INTERVAL))
    count = 0
    while True:
        try:
            nowTime, status = deadline.do_fix_time()
            if status:
                Log.v('当前时间:%s 处于23点到6点之间,12306处于维护状态,暂不处理下单业务' % nowTime)
                continue

            count += 1
            Log.v('第%d次访问12306网站' % count)
            print('-' * 40)
            ticketDetails = Query.loopQuery(TRAIN_DATE, FROM_STATION, TO_STATION,
                                            TrainUtils.passengerType2Desc(passengerTypeCode),
                                            TRAINS_NO,
                                            seatTypesCode, PASSENGERS_ID,leave_time, POLICY_BILL, QUERY_TICKET_REFERSH_INTERVAL)
            status = check_re_login()
            if not status:
                #非登录状态有票,仅支持自动登录或第三方AI自动登录
                if SELECT_AUTO_CHECK_CAPTHCA == CAPTCHA_CHECK_METHOD_HAND:
                    Log.e("手动模式登录状态已过期,请手动重试...")

                status, login = do_login()
                if not status:
                    Log.e("登录状态已过期,重试登录失败")
                    love.change_offline_status(True)
                    return

            # Log.v('已为您查询到可用余票:%s' % ticketDetails)
            Log.v('已为您查询到可用余票:[日期:%s,车次:%s,出发站:%s,到达站:%s,出发时间:%s,到达时间:%s]' % (ticketDetails.custom_date,ticketDetails.trainNo,ticketDetails.fromStation,ticketDetails.toStation,ticketDetails.leaveTime,ticketDetails.arriveTime))

            ticketDetails.passengersId = PASSENGERS_ID
            ticketDetails.ticketTypeCodes = passengerTypeCode
            ticketDetails.tourFlag = TOUR_FLAG if TOUR_FLAG else 'dc'
            submit = Submit(ticketDetails)
            seats_default = copy.deepcopy(CHOOSE_SEATS)
            if (ticketDetails.seatType == SEAT_TYPE[SeatName.FIRST_CLASS_SEAT] or ticketDetails.seatType == SEAT_TYPE[SeatName.SECOND_CLASS_SEAT]) and not seats_default:
                results_seat = []
                for i in range(len(PASSENGERS_ID)):
                    random_seat = random.choice(NUM_SEAT)+random.choice(LETTER_SEAT)
                    if random_seat in results_seat:
                        continue
                    results_seat.append(random_seat)
                seats_default.extend(results_seat)

            if submit.submit(seats_default):
                status, contents = submit.showSubmitInfoPretty()
                if status:
                    Log.v("获取车票详情成功")
                    flag = send_mail(mail_user, mailto_list, '12306订票结果通知', mail_host, mail_user, mail_pass, contents)
                    if flag:
                        Log.v("邮件发送成功!")
                    else:
                        Log.v("邮件发送失败!")

                sms_id = send_sms(ACCOUNT_SID,AUTO_TOKEN,FROM_NUM,TO_NUM,'小机机已经成功拿到小票票,请主人记得在30分钟内完成支付!!!')
                if sms_id:
                    Log.v("短信提醒发送成功!")
                else:
                    Log.v("短信提醒发送失败!")
                break
            time.sleep(1)
        except Exception as e:
            Log.w(e)
    login.loginOut()
    Log.d('注销登录成功')
    love.change_offline_status(True)