Beispiel #1
0
 def send(self, timeout=None):
     timeout = timeout if timeout else self.timeout
     logger.debug('SEND: %s, %s', self.req.get_full_url(),
                  self.req.get_data())
     stime = time.time()
     rsp = urllib2.urlopen(self.req, timeout=timeout)
     logger.debug('[%s] waste time [%f]' % (type(self), time.time() - stime))
     return rsp
Beispiel #2
0
def query_incomplete_order_with_login(username, passwd):
    res = NoCompleteOrderResource()
    try:
        return res.process()
    except NotLogin:
        logger.debug('not loged in, login and try again')
        login(username, passwd)
        return res.process()
Beispiel #3
0
def query_incomplete_order_with_login(username, passwd):
    res = NoCompleteOrderResource()
    try:
        return res.process()
    except NotLogin:
        logger.debug('not loged in, login and try again')
        login(username, passwd)
        return res.process()
Beispiel #4
0
 def send(self, timeout=None):
     timeout = timeout if timeout else self.timeout
     logger.debug('SEND: %s, %s', self.req.get_full_url(),
                  self.req.get_data())
     stime = time.time()
     rsp = urllib2.urlopen(self.req, timeout=timeout)
     logger.debug('[%s] waste time [%f]' %
                  (type(self), time.time() - stime))
     return rsp
Beispiel #5
0
def submit_order(ticket, date, passengers_newstr, passengers_oldstr):
    newstr = passengers_newstr
    oldstr = passengers_oldstr
    # 1. 预订
    submit_order_res = SubmitOrderResource(ticket.secretStr, date,
                                           ticket.from_station_name,
                                           ticket.to_station_name)
    submit_order_res.process()

    # 2. 获取token和key
    submit_token_res = SubmitTokenResource()
    token, key = submit_token_res.process()

    # 3. 输入提交订单的验证码
    for i in xrange(10):
        try:
            passcode = validate_passcode('passenger',
                                         'randp',
                                         _json_att='',
                                         REPEAT_SUBMIT_TOKEN=token)
            break
        except ValidateError:
            logger.debug('validate error')
    else:
        raise ValidateError

    # 4. 检查订单信息
    check_order_res = CheckOrderResource(newstr, oldstr, passcode, token)
    check_order_res.process()

    # 5. 提交订单
    confirm_order_res = ConfirmOrderResource(newstr, oldstr, passcode, key,
                                             token, ticket.yp_info,
                                             ticket.location_code)
    confirm_order_res.process()

    # 6. 获取订单ID
    for i in range(10):
        query_order_res = QueryOrderResource(token)
        order_id = query_order_res.process()
        if order_id:
            break
        time.sleep(1)
    else:
        raise QueryOrderError

    # 7. 查询订单情况
    order_result_res = OrderResultResource(order_id, token)
    order_result_res.process()
    '''
Beispiel #6
0
def get_ticket(date, src, dst, train, seat, num=1, retry_times=10000):
    # deprecated!
    for i in xrange(retry_times):
        logger.debug('try select ticket: %d', i + 1)
        ticket_res = TicketResource(date, src, dst)
        tickets = ticket_res.process()
        try:
            ticket = select_specific_ticket(tickets, train, seat, num)
            return ticket
        except TicketSoldOut:
            logger.info('sold out!!')
            time.sleep(1)
    else:
        raise TicketSoldOut('try times[%d]' % retry_times)
Beispiel #7
0
def get_ticket(date, src, dst, train, seat, num=1, retry_times=10000):
    # deprecated!
    for i in xrange(retry_times):
        logger.debug('try select ticket: %d', i + 1)
        ticket_res = TicketResource(date, src, dst)
        tickets = ticket_res.process()
        try:
            ticket = select_specific_ticket(tickets, train, seat, num)
            return ticket
        except TicketSoldOut:
            logger.info('sold out!!')
            time.sleep(1)
    else:
        raise TicketSoldOut('try times[%d]' % retry_times)
Beispiel #8
0
def submit_order(ticket, date, passengers_newstr, passengers_oldstr):
    newstr = passengers_newstr
    oldstr = passengers_oldstr
    # 1. 预订
    submit_order_res = SubmitOrderResource(ticket.secretStr, date, ticket.from_station_name, ticket.to_station_name)
    submit_order_res.process()

    # 2. 获取token和key
    submit_token_res = SubmitTokenResource()
    token, key = submit_token_res.process()

    # 3. 输入提交订单的验证码
    for i in xrange(10):
        try:
            passcode = validate_passcode('passenger', 'randp', _json_att='', REPEAT_SUBMIT_TOKEN=token)
            break
        except ValidateError:
            logger.debug('validate error')
    else:
        raise ValidateError

    # 4. 检查订单信息
    check_order_res = CheckOrderResource(newstr, oldstr, passcode, token)
    check_order_res.process()

    # 5. 提交订单
    confirm_order_res = ConfirmOrderResource(newstr, oldstr, passcode, key, token, ticket.yp_info, ticket.location_code)
    confirm_order_res.process()

    # 6. 获取订单ID
    for i in range(10):
        query_order_res = QueryOrderResource(token)
        order_id = query_order_res.process()
        if order_id:
            break
        time.sleep(1)
    else:
        raise QueryOrderError

    # 7. 查询订单情况
    order_result_res = OrderResultResource(order_id, token)
    order_result_res.process()

    '''
Beispiel #9
0
def login(username, passwd, validate_retry=100):
    # 1. 进入登录页面
    AudioResource().process()
    init_res = InitResource()
    init_res.process()

    # 2. 输入验证码
    for i in xrange(validate_retry):
        try:
            login_passcode = validate_passcode('login', 'sjrand')
            break
        except ValidateError:
            logger.debug('validate error! retry!')
    else:
        raise ValidateError('try times[%d]' % validate_retry)

    # 3. 登录
    login_res = LoginResource(username, passwd, login_passcode)
    login_res.process()
Beispiel #10
0
def login(username, passwd, validate_retry=100):
    # 1. 进入登录页面
    AudioResource().process()
    init_res = InitResource()
    init_res.process()

    # 2. 输入验证码
    for i in xrange(validate_retry):
        try:
            login_passcode = validate_passcode('login', 'sjrand')
            break
        except ValidateError:
            logger.debug('validate error! retry!')
    else:
        raise ValidateError('try times[%d]' % validate_retry)

    # 3. 登录
    login_res = LoginResource(username, passwd, login_passcode)
    login_res.process()