py12306 README

The project's README from github.com/pjialin/py12306. As one markdown file: README.md.

🚂 py12306 购票助手

分布式,多账号,多任务购票

Features

使用

py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)

1. 安装依赖

git clone https://github.com/pjialin/py12306

pip install -r requirements.txt

2. 配置程序

cp env.py.example env.py

自动打码

(若快已停止服务,目前只能设置free打码模式) free 已对接到打码共享平台,https://py12306-helper.pjialin.com,欢迎参与分享

语音通知

语音验证码使用的是阿里云 API 市场上的一个服务商,需要到 https://market.aliyun.com/products/56928004/cmapi026600.html 购买后将 appcode 填写到配置中

3. 启动前测试

目前提供了一些简单的测试,包括用户账号检测,乘客信息检测,车站检测等

开始测试 -t

python main.py -t

测试通知消息 (语音, 邮件) -t -n

# 默认不会进行通知测试,要对通知进行测试需要加上 -n 参数 
python main.py -t -n

4. 运行程序

python main.py

参数列表

分布式集群

集群依赖于 redis,目前支持情况

使用

将配置文件的中 CLUSTER_ENABLED 打开即开启分布式

目前提供了一个单独的子节点配置文件 env.slave.py.example 将文件修改为 env.slave.py, 通过 python main.py -c env.slave.py 即可快速启动

Docker 使用

1. 将配置文件下载到本地

docker run --rm pjialin/py12306 cat /config/env.py > env.py
# 或
curl https://raw.githubusercontent.com/pjialin/py12306/master/env.docker.py.example -o env.py

2. 修改好配置后运行

docker run --rm --name py12306 -p 8008:8008 -d -v $(pwd):/config -v py12306:/data pjialin/py12306

当前目录会多一个 12306.log 的日志文件, tail -f 12306.log

Docker-compose 中使用

1. 复制配置文件

cp docker-compose.yml.example docker-compose.yml

2. 从 docker-compose 运行

在docker-compose.yml所在的目录使用命令

docker-compose up -d

Web 管理页面

目前支持用户和任务以及实时日志查看,更多功能后续会不断加入

使用

打开 Web 功能需要将配置中的 WEB_ENABLE 打开,启动程序后访问当前主机地址 + 端口号 (默认 8008) 即可,如 http://127.0.0.1:8008

更新

截图

Web 管理页面

Web 管理页面图片

下单成功

下单成功图片

关于防封

目前查询和登录操作是分开的,查询是不依赖用户是否登录,放在 A 云 T 云容易被限制 ip,建议在其它网络环境下运行

QQ 交流群 780289875,TG 群 Py12306 交流

Online IDE

在 Gitpod 中打开

Thanks

License

Apache License.

py12306 (pjialin/py12306)

Searching Database…

What is this?A self-hosted ticket-grabbing assistant for China's 12306 railway booking site: it watches remaining ticket availability and automatically solves captchas and places orders for you.
Is this a hosted service or something I run myself?Something you host yourself: a long-running Python program (or Docker container) on your own machine that polls 12306 and places orders, with an optional web management UI on port 8008.
How do I get it running?Install Python 3.6+ and the dependencies, then fill your 12306 account and passenger details into the config file. Verify with python main.py -t (add -n to also test notifications), and start it with python main.py. Docker and docker-compose are supported too.
What do I need besides Python?Redis only if you want distributed cluster mode. The captcha feature currently works only in free mode via a shared recognition platform, and voice-call notifications require an appcode bought from the Aliyun API market.
Does automatic captcha solving still work?Only in free mode: the original paid provider (RuoKuai) has shut down, so the app now connects to a free shared captcha-solving platform instead.
Is it safe to run it on a cloud server?The README advises caution: queries and login are separated (queries don't need a logged-in account), but cloud IPs like Alibaba or Tencent Cloud get restricted easily, so it recommends a different network environment.
Is it free to use?Yes — it is open source under the Apache 2.0 license; you may only pay for third-party services it hooks into, like the Aliyun voice-call provider.
Can it run on multiple machines as a cluster?Yes — cluster mode runs on Redis: one master with several slave nodes, automatic failover if the master goes down, and config changes pushed to all slaves without restarts. Enable CLUSTER_ENABLED in the config and start a slave with python main.py -c env.slave.py.
What does the web management page let me see?Users, tasks, and real-time logs. Turn on WEB_ENABLED in the config and open your machine's address on port 8008 after starting; the author says more features are planned.
How will I know when it has booked a ticket?It can call you with a voice message (via an Aliyun API-market provider), send email, DingTalk, Telegram, or WeChat push through ServerChan and PushBear. Test them with python main.py -t -n before launch day.
Does it support querying several dates or stations at once?Yes. It can query remaining tickets across multiple dates, a single task can cover multiple stations, and it runs multiple accounts, tasks, and threads in parallel.
Creator
pjialin
Size
2.4 MB
Stars
15K
Age
7y
Commits · 90 Days