def main(): login = Login() Log.v('正在登录...') result, msg = login.login(USER_NAME, USER_PWD) 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' while True: # 死循环一直查票,直到下单成功 try: print('-' * 40) ticketDetails = Query.loopQuery(TRAIN_DATE, FROM_STATION, TO_STATION, TrainUtils.passengerType2Desc(passengerTypeCode), TRAINS_NO, seatTypesCode) 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(): submit.showSubmitInfoPretty() break time.sleep(1) except Exception as e: Log.w(e) print(login.loginOut())
def main(): 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())
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())
def do_login(): EasyHttp.removeCookies() login = Login() Log.v('正在登录...') result, msg = login.login(USER_NAME, USER_PWD, SELECT_AUTO_CHECK_CAPTHCA) EasyHttp.save_cookies(COOKIE_SAVE_ADDRESS) if not Utils.check(result, msg): return False,login Log.v('%s,登录成功' % msg) return True,login
'%s:%s' % (name, code) for name, code in PASSENGER_TICKET_TYPE_CODES.items() ])).strip() or '1' passengersId = input('请输入乘客身份证号(多个以,分隔): ').strip().split(',') tourFlag = input('单程:%s,往返:%s(默认%s): ' % (TourFlag.SINGLE, TourFlag.GO_BACK, TourFlag.SINGLE)).strip() or TourFlag.SINGLE Log.d('出发日期: %s,座位类别: %s,乘客类型: %s,车票类型: %s' % (trainDate, seatTypesCode, passengerTypeCode, tourFlag)) session = requests.session() login = Login(session) for count in range(1, 10, 1): Log.v('[%d]正在进行登录...' % count) result, msg = login.login(userName, userPwd, type=(count - 1) % 2) if Utils.check(result, msg): break Log.w('登录失败,正在重新进行登录...') if not Utils.check(login.isLogin(), '登录失败,程序退出!'): exit(-1) Log.v('%s,登录成功' % msg) ticketDetails = Query.loopQuery( session, trainDate, fromStation, toStation, TrainUtils.passengerType2Desc(passengerTypeCode), seatTypesCode) if not Utils.check(ticketDetails, '刷票失败!'): exit(-1) Log.v('已为您查询到可用余票:%s' % ticketDetails) ticketDetails.passengersId = passengersId ticketDetails.ticketTypeCodes = passengerTypeCode