tickets.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pythonSpider 作者: sheldon9527 项目源码 文件源码
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('????')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号