It is the semi-annual examination season again. For those students who go out to study, they are more nervous than to buy a ticket home. I believe many groups have been occupied by the following picture recently.

Now, as 12306’s ability to resist pressure is becoming stronger and stronger, a variety of third-party ticketing software is emerging in an endless stream, what zhixing train, Ctrip travel, even the official launch of accelerated services, which led to a large number of scalpers are beginning to sigh: this year’s business is not good to do cough up!

And now the way to grab tickets are the eight impassants across the sea, each show their powers, this let you buy accelerated package consumption, that let you crazy to promote, so that there was the acceleration of the small program crazy explosion group (wechat small program fear into the biggest winner).

As a frustrated student party, it is impossible to spend money on a speed bag, after all, it costs nearly half of a train ticket. Let me crazy with small program explosion group is unlikely, after all, related to their social credibility, and now the members of the group are all big ye, do not send red envelopes do not speed up.

So isn’t there some geeky ticket-snatching app?

12306 ticket assistant

Want to seek the software of all sorts of SAO operation, the first idea nature is to go the website of biggest same sex making friends, discovered accidentally the project that is named 12306 buy ticket small assistant, tried to grab ticket really actually, the project has been open source, address 👉github.com/testerSunsh…

Thinking figure

The author is also very carefully to the process of thinking to draw out, we can simply take a look. The whole idea is to simulate a normal way of buying tickets, tickets remaining under the first query, submit orders if there is a seat, a captcha this identification authentication code, then click the submit button, here the author did a lot of conditions, such as abnormal to query, submit orders, failure to query, until you get the order successfully. There is also a notification mechanism for successful booking, which is sent to your email.

use

Having said that, how do you use it? For details, please refer to the author’s README. Here I will explain what to pay attention to and how to use the ticket assistant in the simplest way:

Matters needing attention

  1. The Python version is 2.7.10-2.7.15
  2. MacOS/Linux is recommended
  3. Make sure to run it as the root user

The preparatory work

  1. If registered fast image recognition www.ruokuai.com/client/inde… , remember the user name and password, and then recharge 1 yuan for 2500 fast beans, this step is to identify the verification code to prepare.
  2. Download project: Executegit clone https://github.com/testerSunshine/12306.gitDownload the code locally.
  3. Install Python2.7: It is recommended that you use PyEnv to manage your Version of Python. For Mac users, you can use PyEnv to manage Multiple Versions of Python on Mac. I am using Python 2.7.15
  4. Install the dependency library: command line after entering the project root directory, runsudo python2 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

Project configuration

The **ticket_config.yaml** in the figure above is the most important configuration file for running the whole project. All the ticket purchase information is contained in this file, such as ticket time, 12306 account password, passenger information, notification mailbox, etc. There are detailed notes in the file, which can be changed as required.

After filling out the configuration file according to your requirements, you are ready to run.

Started to vote

Once in the project root directory, execute sudo Python run.py to start snatching tickets.

If you get a ticket, it prints something like the following log:

Train number: DXXX departure station: Nanjing South Terminal: Hefei South second class seat: 16 set the number of passengers as: 1 query to more tickets, try to submit the order ticket submitted through, trying to queue up successfully, you are in: 0, the current remaining tickets are still remaining: 16 do not need verification code to submit the order successfully! Congratulations, you have booked your ticket successfully. The order number is XXXXXX. Please open your browser and log in to 12306.Copy the code

Then go to 12306’s official website and visit ‘Outstanding Orders’ to see your ticket information.

Finally, I wish everyone can grab the ticket to go home!