예제 #1
0
파일: Query.py 프로젝트: xzgxp/EasyTrain
 def query(session,
           trainDate,
           fromStation,
           toStation,
           passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r'leftTicketDTO.train_date': trainDate,
         r'leftTicketDTO.from_station': city2code(fromStation),
         r'leftTicketDTO.to_station': city2code(toStation),
         r'purpose_codes': passengerType
     }
     # response = NetUtil.normalGet(Query.__url, params=params, headers={'User-Agent': random.choice(USER_AGENT)}).json()
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': r'https://kyfw.12306.cn/otn/leftTicket/init',
         'Connection': 'keep-alive',
     }
     response = NetUtils.get(session,
                             Query.__url,
                             params=params,
                             headers=headers,
                             verify=False)
     print(response.text)
     response = response.json()
     response = response['data'] if 'data' in response else Log.e(
         "can not find key: 'data'")
     queryResults = response['result'] if 'result' in response else Log.e(
         "can not find key: 'result'")
     return Query.__decode(queryResults, passengerType)
예제 #2
0
파일: Query.py 프로젝트: wolfyun/EasyTrain
 def query(trainDate, fromStation, toStation, passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r'leftTicketDTO.train_date': trainDate,
         r'leftTicketDTO.from_station': city2code(fromStation),
         r'leftTicketDTO.to_station': city2code(toStation),
         r'purpose_codes': passengerType
     }
     jsonRet = EasyHttp.send(queryUrls['query'], params=params)
     try:
         if jsonRet:
             return Query.__decode(jsonRet['data']['result'], passengerType)
     except Exception as e:
         Log.e(e)
     return []
예제 #3
0
파일: Query.py 프로젝트: weaming/EasyTrain
 def query(trainDate,
           fromStation,
           toStation,
           passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r"leftTicketDTO.train_date": trainDate,
         r"leftTicketDTO.from_station": city2code(fromStation),
         r"leftTicketDTO.to_station": city2code(toStation),
         r"purpose_codes": passengerType,
     }
     jsonRet = EasyHttp.send(queryUrls["query"], params=params)
     try:
         if jsonRet:
             return Query.__decode(jsonRet["data"]["result"], passengerType)
     except Exception as e:
         Log.e(e)
     return []
예제 #4
0
파일: Query.py 프로젝트: xzgxp/EasyTrain
 def __query(trainDate,
             fromStation,
             toStation,
             passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r'leftTicketDTO.train_date': trainDate,
         r'leftTicketDTO.from_station': city2code(fromStation),
         r'leftTicketDTO.to_station': city2code(toStation),
         r'purpose_codes': passengerType
     }
     response = NetUtils.normalGet(Query.__url,
                                   params=params,
                                   headers={
                                       'User-Agent':
                                       random.choice(USER_AGENT)
                                   }).json()
     response = response['data'] if 'data' in response else Log.e(
         "can not find key: 'data'")
     queryResults = response['result'] if 'result' in response else Log.e(
         "can not find key: 'result'")
     return Query.__decode(queryResults, passengerType)