Skip to content

KonjacW/ticket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Damai Countdown Bot (Xiaomi + Windows)

Scope

This tool automates the purchase flow only until Alipay payment page appears and then exits.

Main flow:

  1. Wait on the event page and OCR-read countdown.
  2. When countdown hits 0, start rapid tapping by text recognition:
    • 立即预订 -> 确定 -> 立即提交
  3. If refresh page appears (努力刷新), keep clicking refresh until recovered.
  4. Stop immediately after detecting success keywords:
    • 支付宝支付 / 确认付款

Parallel mode (enabled by default):

  1. ADB screenshot + OCR chain keeps monitoring countdown and predicts near-zero trigger.
  2. Phone-side local service chain (uiautomator2 server) continuously checks key button texts.
  3. Once rush state is triggered, local service chain taps buttons/fallback points in parallel with OCR chain.

Project Files

  • main.py: entrypoint
  • config/config.yaml: behavior and region config
  • damai_bot/config.py: config parsing
  • damai_bot/ocr_utils.py: OCR + countdown parsing
  • damai_bot/bot.py: state machine and tap logic

Prerequisites

  1. Windows with Python 3.10+
  2. Xiaomi phone with USB debugging enabled
  3. ADB available in PATH
  4. Damai app package: cn.damai

Install

pip install -r requirements.txt
python -m uiautomator2 init

Windows (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 init

Run

python main.py --config config/config.yaml

Windows (use your specified interpreter):

& "C:/Users/KonjacW/PyCharmMiscProject/.venv/Scripts/python.exe" main.py --config config/config.yaml

If multiple devices are connected:

python main.py --config config/config.yaml --serial <adb-serial>

Recommended Device Setup

  1. Keep screen on and unlocked.
  2. Disable battery optimization for Damai.
  3. Turn off auto-rotate.
  4. Keep network stable and avoid switching between Wi-Fi and mobile data.

Calibration Notes

  • regions.countdown_roi is a normalized rectangle for countdown OCR.
  • fallback_points are normalized points used when text detection fails.
  • Because Damai theme colors vary, this bot uses text recognition first, not color matching.
  • device.adb_path can point to adb.exe when adb is not in PATH.
  • device.click_safe_bottom_margin_ratio reserves 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.

Safety

  • The bot does not auto-pay.
  • As soon as payment page text is detected, it exits.

Troubleshooting

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 -l

Then on phone (Xiaomi):

  1. Enable Developer options and USB debugging.
  2. Set USB mode to File Transfer (MTP).
  3. Replug USB and accept the RSA authorization popup (always allow).
  4. Run adb devices -l again until state is device (not unauthorized / empty).

If python -m uiautomator2 init fails with INSTALL_FAILED_USER_RESTRICTED on Xiaomi:

  1. Enable USB 安装 in Developer options.
  2. Enable USB 调试(安全设置) if available.
  3. Keep the screen unlocked and accept installation prompts on phone.

If logs show SecurityException ... INJECT_EVENTS and buttons are not actually pressed:

  1. Open Developer options and enable USB 调试(安全设置).
  2. In Xiaomi security prompts, allow USB debugging control / simulated taps.
  3. Replug USB cable and re-authorize the computer.
  4. Verify by running:
    • adb shell input tap 1 1
    • If command still prints INJECT_EVENTS, the phone is still blocking automation taps.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages