本文整理匯總了Python中stations.stations.get方法的典型用法代碼示例。如果您正苦於以下問題:Python stations.get方法的具體用法?Python stations.get怎麽用?Python stations.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stations.stations
的用法示例。
在下文中一共展示了stations.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: command
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def command():
arguments = docopt(__doc__)
#print(arguments)
from_sta = stations.get(arguments['<from>'])
to_sta = stations.get(arguments['<to>'])
date = arguments['<date>']
url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date, from_sta, to_sta)
resp = requests.get(url, verify=False)
#print(resp.json())
options = ''.join([
key for key, value in arguments.items() if value is True
])
available_trains = resp.json()['data']
TrainsResult(available_trains, options).pretty_print()
示例2: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
"""Command-line interface"""
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
url = ('https://kyfw.12306.cn/otn/leftTicket/query?'
'leftTicketDTO.train_date={}&'
'leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT').format(
date, from_station, to_station
)
options = ''.join([
key for key, value in arguments.items() if value is True
])
r = requests.get(url, verify=False)
res = r.json()
if 'data' in res.keys():
available_trains = res['data']
TrainsCollection(available_trains, options).pretty_print()
else:
print('????')
示例3: query_by_command
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def query_by_command(self):
"""command-line interface"""
arguments = docopt(__doc__)
from stations import stations
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
train_type = []
all_train_type = ['-d', '-g', '-t', '-k', '-z']
for key in all_train_type:
if arguments[key]:
train_type.append(key[1:].upper())
if len(train_type) == 0:
train_type = [x[1:].upper() for x in all_train_type]
date = arguments['<date>']
# ??URL
url = 'https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate={}&from_station={}&to_station={}'.format(date,from_station, to_station)
import requests
requests.packages.urllib3.disable_warnings()
r = requests.get(url, verify = False)
rows = r.json()['data']['datas']
from ticketSearch import TrainCollection
t = TrainCollection(rows, train_type)
t.print_pretty()
示例4: search
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def search():
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
# ??URL
url = 'https://kyfw.12306.cn/otn/leftTicket/queryA?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(
date, from_station, to_station
)
options = ''.join([key for key, value in arguments.items() if value is True])
requests.packages.urllib3.disable_warnings()
r = requests.get(url, verify=False)
available_trains = r.json()['data']
TrainsCollection(available_trains, options).pretty_print()
示例5: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
"""command-line interface"""
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(
date, from_station, to_station)
r = requests.get(url, verify=False)
available_trains = r.json()['data']['result']
available_place = r.json()['data']['map']
options = ''.join([
key for key, value in arguments.items() if value is True
])
TrainsCollection(available_trains,available_place, options).pretty_print()
示例6: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
"""command-line interface"""
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
global date
date = arguments['<date>']
# ??URL
url = 'https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate={}&from_station={}&to_station={}'.format(
date, from_station, to_station
)
#print(url)
r = requests.get(url, verify=False)
rows = r.json()['data']['datas']
#print(r.json())
trains = TrainCollection(rows)
trains.pretty_print()
示例7: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
"""command-line interface"""
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
# URL
url = 'https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate={}&from_station={}&to_station={}'.format(
date, from_station, to_station
)
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
r = requests.get(url,verify = False)
print(r)
rows = r.json()['data']['datas']
trains = TrainCollection(rows)
trains.pretty_print()
示例8: _get_duration
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def _get_duration(self, raw_train):
duration = raw_train.get('lishi').replace(':', '??') + '?'
if duration.startswith('00'):
return duration[4:]
if duration.startswith('0'):
return duration[1:]
return duration
示例9: _get_duration
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def _get_duration(self, raw_train):
duration = raw_train.get('lishi').replace(':', '??') + '?'
if duration.startswith('00'):
return duration[4:]
if duration.startswith('0'):
return duration[1:]
return duration
示例10: _get_duration
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def _get_duration(self, raw_train):
duration = raw_train.get('lishi').replace(':','??')+'?'
if duration.startswith('00'):
return duration[4:]
if duration.startswith('0'):
return duration[1:]
return duration
示例11: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date,from_station,to_station)
options = ''.join([key for key,value in arguments.items() if value is True])
r = requests.get(url,verify=False)
available_trains = r.json()['data']
TrainsCollection(available_trains,options).pretty_print()
示例12: _get_duration
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def _get_duration(self, raw_train):
duration = raw_train['queryLeftNewDTO'].get('lishi').replace(':', '??') + '?'
if duration.startswith('00'):
return duration[4:]
if duration.startswith('0'):
return duration[1:]
return duration
示例13: cli
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def cli():
arguments = docopt(__doc__)
from_station = stations.get(arguments['<from>'])
to_station = stations.get(arguments['<to>'])
date = arguments['<date>']
url = 'https://kyfw.12306.cn/otn/leftTicket/queryZ?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(
date, from_station, to_station)
options = ''.join([
key for key, value in arguments.items() if value is True
])
r = requests.get(url, verify=False)
available_trains = r.json()['data']
TrainsCollection(available_trains, options).pretty_print()
示例14: colored
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def colored(color, text):
table = {
'red': '\033[91m',
'green': '\033[92m',
# no color
'nc': '\033[0m'
}
cv = table.get(color)
nc = table.get('nc')
return ''.join([cv, text, nc])
示例15: _get_duration
# 需要導入模塊: from stations import stations [as 別名]
# 或者: from stations.stations import get [as 別名]
def _get_duration(self, row):
"""
????????
"""
duration = row.get('lishi').replace(':', 'h') + 'm'
if duration.startswith('00'):
return duration[4:]
if duration.startswith('0'):
return duration[1:]
return duration