本文整理汇总了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