Beispiel #1
0
def working(username=USER_NAME, password=USER_PWD, id_cards=PASSENGERS_ID, day=TRAIN_DATE, from_station=FROM_STATION,
            to_station=TO_STATION,
            seats=SEAT_TYPE_CODE, types=PASSENGER_TYPE_CODE, train_no=TRAINS_NO, polocy=POLICY_BILL,
            tour_flag=TOUR_FLAG, refersh=QUERY_TICKET_REFERSH_INTERVAL):
    GetFreeProxy.getAllProxy(THREAD_POOL_SIZE, THREAD_OR_PROCESS, IS_REFASH_IP_POOL)
    init_ip_pool()
    login = Login()
    Log.v('正在登录...')
    result, msg = login.login(username, password, IS_AUTO_CHECK_CAPTHCA)
    if not Utils.check(result, msg):
        Log.e(msg)
        return
    Log.v('%s,登录成功' % msg)

    seatTypesCode = seats if seats else [SEAT_TYPE[key] for key in SEAT_TYPE.keys()]
    passengerTypeCode = types if types else '1'

    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(day, from_station, to_station,
                                            TrainUtils.passengerType2Desc(passengerTypeCode),
                                            train_no,
                                            seatTypesCode, id_cards, polocy, refersh)
            Log.v('已为您查询到可用余票:%s' % ticketDetails)

            ticketDetails.passengersId = id_cards
            ticketDetails.ticketTypeCodes = passengerTypeCode
            ticketDetails.tourFlag = tour_flag if tour_flag else 'dc'
            submit = Submit(ticketDetails)
            if submit.submit(CHOOSE_SEATS):
                status, contents = submit.showSubmitInfoPretty()
                if status:
                    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)
    print(login.loginOut())
Beispiel #2
0
def main():

    GetFreeProxy.getAllProxy(THREAD_POOL_SIZE,THREAD_OR_PROCESS,IS_REFASH_IP_POOL)
    sqlite = Sqlite(address + 'ip.db')
    ips_results = sqlite.query_data('select proxy_adress from ip_house')

    login = Login()
    Log.v('正在登录...')
    result, msg = login.login(USER_NAME, USER_PWD, IS_AUTO_CHECK_CAPTHCA)
    if not Utils.check(result, msg):
        Log.e(msg)
        return
    Log.v('%s,登录成功' % msg)

    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'

    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, POLICY_BILL, QUERY_TICKET_REFERSH_INTERVAL)
            Log.v('已为您查询到可用余票:%s' % ticketDetails)

            ticketDetails.passengersId = PASSENGERS_ID
            ticketDetails.ticketTypeCodes = passengerTypeCode
            ticketDetails.tourFlag = TOUR_FLAG if TOUR_FLAG else 'dc'
            submit = Submit(ticketDetails)
            if submit.submit(CHOOSE_SEATS):
                status, contents = submit.showSubmitInfoPretty()
                if status:
                    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)
    print(login.loginOut())
Beispiel #3
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_status(True)
            return
    else:
        if not ('uamtk' in cookies and 'RAIL_DEVICEID' in cookies):
            status,login = do_login()
            if not status:
                love.change_status(True)
                return
        else:
            status = check_login()
            if not status:
                love.change_status(True)
                return
            login = Login()
            login._urlInfo = loginUrls['normal']
            Log.v('已登录状态,开始寻找小票票')

    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)
            flag,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,HEART_BEAT_PER_REQUEST_TIME)
            #非登录状态有票,仅支持自动登录或第三方AI自动登录
            if not flag:
                if SELECT_AUTO_CHECK_CAPTHCA == CAPTCHA_CHECK_METHOD_HAND:
                    Log.e("手动验证模式登录重试失败,请手动重试")
                    return

                status, login = do_login()
                if not status:
                    Log.e("自动验证模式登录重试失败自动登录失败,请手动重试")
                    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_status(True)
Beispiel #4
0
def main():
    #免费代理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')
    #当前实际显示有效时间为4天,实际访问可下单时间大概为2天(细节可按实际情况调节)
    if 'RAIL_EXPIRATION' in cookies and (int(RAIL_EXPIRATION) -
                                         172800000) < int(time.time() * 1000):
        Log.v('cookie登录已过期,重新请求')
        EasyHttp.removeCookies()
        status, login = do_login()
        if not status:
            return
    else:
        if not ('uamtk' in cookies and 'RAIL_DEVICEID' in cookies):
            status, login = do_login()
            if not status:
                return
        else:
            login = Login()
            Log.v('已登录状态,开始寻找小票票')

    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'

    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, POLICY_BILL,
                QUERY_TICKET_REFERSH_INTERVAL)
            Log.v('已为您查询到可用余票:%s' % ticketDetails)

            ticketDetails.passengersId = PASSENGERS_ID
            ticketDetails.ticketTypeCodes = passengerTypeCode
            ticketDetails.tourFlag = TOUR_FLAG if TOUR_FLAG else 'dc'
            submit = Submit(ticketDetails)
            if submit.submit(CHOOSE_SEATS):
                status, contents = submit.showSubmitInfoPretty()
                if status:
                    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('注销登录成功')
Beispiel #5
0
def main():
    #免费代理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:
            return
    else:
        if not ('uamtk' in cookies and 'RAIL_DEVICEID' in cookies):
            status, login = do_login()
            if not status:
                return
        else:
            response = EasyHttp.post_custom(loginUrls['normal']['conf'])
            if not response or not response.json():
                Log.d('登录状态检查失败,重新请求')
                status, login = do_login()
                if not status:
                    return
            resp = response.json()
            login_status = resp.get('data').get('is_login')
            Log.d('登录状态:%s' % login_status)
            if 'Y' != login_status:
                Log.d('登录状态已过期,重新请求')
                status, login = do_login()
                if not status:
                    return
            login = Login()
            login._urlInfo = loginUrls['normal']
            Log.v('已登录状态,开始寻找小票票')

    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'

    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, POLICY_BILL,
                QUERY_TICKET_REFERSH_INTERVAL)
            Log.v('已为您查询到可用余票:%s' % ticketDetails)

            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
                    == 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:
                    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('注销登录成功')
Beispiel #6
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}

    if 'uamtk' not in cookies or 'RAIL_DEVICEID' not in cookies:
        status, login = do_login(love)
        if not status:
            love.change_offline_status(True)
            return
    else:
        status, _ = check_user_login()
        if not status:
            status, login = do_login(love)
            if not status:
                love.change_offline_status(True)
                return

        Log.v('已登录状态,开始寻找小票票')

    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]" %
          (','.join(TRAIN_DATE), FROM_STATION, TO_STATION,
           '/出发时间段[' + '~'.join(leave_time) + ']' if leave_time else '',
           '/车次[' + ','.join(TRAINS_NO) + ']' if TRAINS_NO else '',
           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 = love.get_login_status()
            # status,_ = check_user_login()
            if not status:
                #非登录状态有票,仅支持自动登录或第三方AI自动登录
                if SELECT_AUTO_CHECK_CAPTHCA == CAPTCHA_CHECK_METHOD_HAND:
                    Log.e("手动模式登录状态已过期,请手动重试...")

                status, login = do_login(love)
                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 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)