How hobr/transition-ticket works
Project type and purpose
• This is a command-line Python tool (“Transition Ticket”) whose goal is to automate the process of fetching Bilibili “back-in-stock” tickets.
• It orchestrates login, polling Bilibili APIs, handling Geetest captchas, and notifying the user via sound alerts.
File structure
• Top-level:
• cli.py – entry point
• interface/CLI – command definitions and argument parsing for “product,” “user,” “setting” commands
• util/ (Bilibili, Captcha, Config, Data, Info, Login, Notice, Request, Task) – core business logic modules
• geetest/ – embedded static HTML/JS/CSS to drive the Geetest captcha flow in a headless or browser-driven environment
• assets/alarm.wav – local notification asset
• cli.spec, pyproject.toml, requirements.txt, packaging/config scripts – build and deployment
README
• Confirms Python 3.11–3.14, uses PortAudio for audio alerts, runs as a CLI, uses a finite‐state‐machine (FSM) to drive the “run” flow (see assets/fsm.png).
• Describes manual installation, external dependencies (Edge browser for captcha), and build steps via PyInstaller.
Main components
a. CLI Layer
• cli.py
• interface/CLI/product.py, user.py, setting.py
b. Core Logic Layer (util packages)
• util/Login (handles authentication, browser-driven or credentials)
• util/Request (wraps HTTP calls to Bilibili endpoints)
• util/Captcha & geetest/ (handles loading and solving Geetest challenges)
• util/Task (polling loop or scheduler implementing the FSM)
• util/Notice (sound alerts via PortAudio using assets/alarm.wav)
• util/Config/Data/Info/Bilibili – support modules for configuration, parsing, and data models
c. External Services & Dependencies
• Bilibili ticket APIs (HTTP endpoints)
• Geetest captcha service (embedded front-end + JS hooks)
• PortAudio/native audio drivers
• PyPI (for pip installs, packaging via PyInstaller)
Relationships and data flows
• User invokes cli.py → CLI Layer parses commands → dispatches to Core Logic
• Core Logic uses util/Config to load settings, util/Login to authenticate
• Upon login success, util/Task FSM kicks in, util/Request polls Bilibili endpoints
• If Geetest challenge issued → util/Captcha + geetest/ front-end component handle solving → back to util/Request
• Upon ticket availability or errors → util/Notice emits alarm.wav via PortAudio
• Data (user credentials, settings, last-seen IDs) stored in util/Data or util/Config
Architectural patterns and principles
• Layered architecture (Interface → Core Logic → External Services)
• Adapter/Wrapper pattern for HTTP and audio subsystems
• Finite-state-machine for orchestrating the polling and retry logic
• Single process, modular Python packages for separation of concerns