How pjialin/py12306 works
py12306 is a multi-account, distributed 12306 ticket-buying assistant. Its core workflow maintains user sessions, queries configured routes and dates for available seats, then submits an order; captcha handling and notifications support that flow. Configuration can change at runtime, while optional Redis coordination synchronizes cluster state and messages. The README also documents a web management interface. Some subsystem links are based on the SOURCE INDEX or README rather than complete excerpts; uncertain runtime wiring is omitted.
Main entry points: job.py Availability search · app.py Application runtime · cluster.py Cluster coordinator · handler Web handlers
Components 22
Runtime orchestration
- Application runtime
py12306/app.py - Runtime configuration
py12306/config.py
Ticket workflow
- Query coordinator
py12306/query/query.py - Availability search
py12306/query/job.py - User coordinator
py12306/user/user.py - Account session
py12306/user/job.py - Captcha handling
py12306/helpers/auth_code.py - Order submission
py12306/order/order.py
Coordination and services
- HTTP session
py12306/helpers/request.py - 12306 API endpoints
py12306/helpers/api.py - Cluster coordinator
py12306/cluster/cluster.py - Redis state
py12306/cluster/redis.py - Runtime events
py12306/helpers/event.py - CDN discovery
py12306/helpers/cdn.py - Logging
py12306/log/base.py - Notifications
py12306/helpers/notification.py
Management interface
- Web server
py12306/web/web.py - Web handlers
py12306/web/handler
Other components
- Operator
- Web user
- 12306 service
- Notification services
Connections 27
- Operator → Application runtime: starts
- Application runtime → Runtime configuration: loads
py12306/app.py - Query coordinator → Availability search: creates jobs
py12306/query/query.py - Availability search → 12306 service: queries availability
py12306/query/job.py - Availability search → Order submission: submits order
py12306/query/job.py - Availability search → User coordinator: gets passengers
py12306/query/job.py - User coordinator → Account session: creates sessions
py12306/user/user.py - Account session → Captcha handling: uses captcha
py12306/user/job.py - Account session → 12306 service: authenticates
- Order submission → 12306 service: submits booking
- Availability search → Runtime events: destroys completed job
py12306/query/job.py - Application runtime → Notifications: tests notifications
py12306/app.py - Notifications → Notification services: sends messages
- Availability search → CDN discovery: checks CDN
py12306/query/job.py - Availability search → HTTP session: requests tickets
py12306/query/job.py - HTTP session → 12306 service: sends HTTP
py12306/helpers/request.py - Cluster coordinator → Redis state: uses Redis
py12306/cluster/cluster.py - Cluster coordinator → Runtime events: dispatches events
py12306/cluster/cluster.py - Application runtime → Cluster coordinator: initializes when enabled
py12306/app.py - Application runtime → Logging: writes runtime logs
py12306/app.py - Web server → Web handlers: registers handlers
py12306/web/web.py - Web user → Web server: uses management UI
README.md - Web handlers → Query coordinator: manages queries
py12306/web/handler/query.py - Web handlers → User coordinator: manages users
py12306/web/handler/user.py - Web handlers → Logging: reads logs
py12306/web/handler/log.py - Runtime configuration → Cluster coordinator: syncs cluster config
README.md - Cluster coordinator → Logging: syncs node messages
py12306/log/base.py