Python implements the 12306 train ticket queryer and python12306 queryer
12306 train ticket purchasing software has been used by everyone. How to Use Python to write a command line train ticket viewer and require you to run a command line on the command line to obtain the desired train ticket information? Let's take a look at this article.
Python train ticket queryer
Interface settings
Let's give a name to this small application first. Since it is used to query ticket information, it is called tickets.
We hope that users can get the desired information as long as they enter the origin site, arrival site, and date. Therefore, tickets should be used as follows:
$ tickets from to date
Final $ tickets [-gdtkz] from to date
Development Environment
Use virtualenv to create a virtual environment, and use Python3 for development,
$ virtualenv -p /usr/bin/python3 venv
Run the following command to activate it:
$ . venv/bin/activate
Resolution Parameters
Python has many tools for writing command line applications. We use docopt, a simple and easy-to-use tool. We should install it first:
$ pip3 install docopt
Docopt can parse parameters according to the format defined in the document string,
Get Data
Https://kyfw.12306.cn/otn/lcxxcx/query? Purpose_codes = ADULT & queryDate = 2016-07-01 & from_station = SHH & to_station = BJP
Https://kyfw.12306.cn/otn/resources/js/framework/station_name.js? Station_version = 1.8955
Save stations.html
Display result
The prettytable database allows us to format and display data like the MySQL database.
$ pip3 install prettytable
The above section describes how to implement the 12306 Train Ticket finder in python. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!