This tool automates the purchase flow only until Alipay payment page appears and then exits.
Main flow:
- Wait on the event page and OCR-read countdown.
- When countdown hits 0, start rapid tapping by text recognition:
- 立即预订 -> 确定 -> 立即提交
- If refresh page appears (努力刷新), keep clicking refresh until recovered.
- Stop immediately after detecting success keywords:
- 支付宝支付 / 确认付款
Parallel mode (enabled by default):
- ADB screenshot + OCR chain keeps monitoring countdown and predicts near-zero trigger.
- Phone-side local service chain (uiautomator2 server) continuously checks key button texts.
- Once rush state is triggered, local service chain taps buttons/fallback points in parallel with OCR chain.
main.py: entrypointconfig/config.yaml: behavior and region configdamai_bot/config.py: config parsingdamai_bot/ocr_utils.py: OCR + countdown parsingdamai_bot/bot.py: state machine and tap logic
- Windows with Python 3.10+
- Xiaomi phone with USB debugging enabled
- ADB available in PATH
- Damai app package:
cn.damai
pip install -r requirements.txt
python -m uiautomator2 initWindows (use your specified interpreter):
& "C:/Users/KonjacW/PyCharmMiscProject/.venv/Scripts/python.exe" -m pip install -r requirements.txt
& "C:/Users/KonjacW/PyCharmMiscProject/.venv/Scripts/python.exe" -m uiautomator2 initpython main.py --config config/config.yamlWindows (use your specified interpreter):
& "C:/Users/KonjacW/PyCharmMiscProject/.venv/Scripts/python.exe" main.py --config config/config.yamlIf multiple devices are connected:
python main.py --config config/config.yaml --serial <adb-serial>- Keep screen on and unlocked.
- Disable battery optimization for Damai.
- Turn off auto-rotate.
- Keep network stable and avoid switching between Wi-Fi and mobile data.
regions.countdown_roiis a normalized rectangle for countdown OCR.fallback_pointsare normalized points used when text detection fails.- Because Damai theme colors vary, this bot uses text recognition first, not color matching.
device.adb_pathcan point to adb.exe when adb is not in PATH.device.click_safe_bottom_margin_ratioreserves a protected bottom area to avoid tapping navigation buttons.parallel.*controls the phone-side local service worker for dual-path execution.
Low-latency tuning (parallel mode):
parallel.local_scan_interval_seconds: idle scan interval before rush.parallel.local_probe_interval_seconds: heavy text-probe interval during rush.parallel.local_tap_interval_seconds: fallback tap interval during rush hot loop.parallel.local_followup_taps: extra immediate taps after text hit to lock in first action.parallel.stage_sync_interval_seconds: interval for expensive stage sync checks.
- The bot does not auto-pay.
- As soon as payment page text is detected, it exits.
If startup fails with Can't find any android device/emulator:
& "D:/software/platform-tools-latest-windows/platform-tools/adb.exe" kill-server
& "D:/software/platform-tools-latest-windows/platform-tools/adb.exe" start-server
& "D:/software/platform-tools-latest-windows/platform-tools/adb.exe" devices -lThen on phone (Xiaomi):
- Enable Developer options and USB debugging.
- Set USB mode to File Transfer (MTP).
- Replug USB and accept the RSA authorization popup (always allow).
- Run
adb devices -lagain until state isdevice(notunauthorized/ empty).
If python -m uiautomator2 init fails with INSTALL_FAILED_USER_RESTRICTED on Xiaomi:
- Enable
USB 安装in Developer options. - Enable
USB 调试(安全设置)if available. - Keep the screen unlocked and accept installation prompts on phone.
If logs show SecurityException ... INJECT_EVENTS and buttons are not actually pressed:
- Open Developer options and enable
USB 调试(安全设置). - In Xiaomi security prompts, allow USB debugging control / simulated taps.
- Replug USB cable and re-authorize the computer.
- Verify by running:
adb shell input tap 1 1- If command still prints
INJECT_EVENTS, the phone is still blocking automation taps.