#!/usr/bin/env python3
"""
Train tickets query via command-line
Usage:
tickets [-gdtkz]
Options:
-h, --help 显示帮助菜单
-g 高铁
-d 动车
-t 特快
-k 快速
-z 直达
Example:
tickets beijing shanghai 2016-08-25
"""
from docopt import docopt
import re
import requests
from prettytable import PrettyTable
class TrainCollection(object):
# 显示车次、出发/到达站、出发/到达时间、历时、一等座、二等座、软卧、硬卧、硬座
header = 'train station time duration first second softsleep hardsleep hardsit'.split()
def __init__(self, rows):
self.rows = rows
def _get_duration(self, row):
#获取车次运行时间
duration = row.get('lishi').replace(':', 'h') + 'm'
if duration.startswith('00'):
return duration[