Skip to content

Repository files navigation

Reservation Automation Script

A Playwright-based automation script for a configurable web reservation flow.

This repository is intended for personal learning, testing, and automation practice. Configure your own target site locally and avoid committing private credentials, login state, logs, or real service URLs.


Quick Start

  1. Copy pe.config.json.example to pe.config.json.
  2. Fill in your local account, target page URL, login options, and booking preferences.
  3. Run run-pe.bat.
  4. The script will open a browser, check login state, wait until the configured time, switch through the configured booking flow, and attempt the selected reservation.
  5. After submission or failure, the browser remains open until you close it manually.

Private Local Files

Do not commit these files:

  • pe.config.json: local account, real target URL, OTP payload, and booking preferences
  • playwright-state.json: saved browser login state
  • logs/: runtime logs and OCR debug samples
  • .tesseract-cache/: local OCR cache/runtime data

Run Logs

Each run writes terminal output to logs/pe-<timestamp>.log while still printing normally in the terminal. For OCR debugging, the newest log file includes OCR worker startup time plus per-captcha preprocessing, recognition, total time, and confidence.


Site Config

site.entryUrl is the target reservation page URL. Keep the real URL only in your local pe.config.json; the public example uses a placeholder.


Login Modes

login.mode supports:

  • manual: always log in manually
  • storage_state: reuse saved login state first, fallback to manual login if needed
  • otp: generate a dynamic OTP from QR payload and log in automatically

Related config fields:

  • login.saveStorageStateAfterLogin
  • login.captcha.enabled
  • login.captcha.expectedLength
  • login.captcha.maxAttempts
  • login.otp.venueOptionText
  • login.otp.minSecondsRemaining
  • login.otp.qrPayloadBase64

Captcha Handling

When a numeric image captcha appears on the login form:

  • The script captures the captcha image automatically
  • Runs local OCR to recognize it
  • Fills the result into the input field

Retry logic:

  • login.captcha.expectedLength is strictly enforced
  • If the OCR result length is incorrect, the captcha is refreshed immediately
  • If the page shows a captcha-related error, the script refreshes the captcha and retries
  • The script retries up to login.captcha.maxAttempts

OTP is generated after captcha recognition and right before clicking login, reducing the chance of OTP expiration caused by OCR delays.


Browser Config

browser.mode supports:

  • auto: prefer local Chrome/Edge, fallback to Playwright
  • local: force local Chrome/Edge
  • playwright: use browser installed via npx playwright install chromium
  • custom: use path specified in browser.executablePath

Payment Config

payment.autoPay controls whether the script continues automatically into payment after order submission.

When payment.autoPay = true, the script waits for the payment page, selects the leftmost coupon if needed, prints the payable amount, clicks the final payment confirmation button, and keeps the browser open.

When payment.autoPay = false, the script submits the order only, stops before payment, and keeps the browser open for manual handling.


Test Mode Config

Test mode is controlled by test.mode in pe.config.json, so the script does not ask for test mode in the terminal.

  • off: normal reservation flow; submit order; auto-pay follows payment.autoPay
  • select_only: test selection flow; select slots and agreement only; skip submit and auto-pay
  • submit_only: test selection flow; submit order; skip auto-pay
  • submit_and_pay: test selection flow; submit order and auto-pay
  • login_fill_only: login-form test flow; keep filling OTP login fields after page load/refresh; never click login

Booking Config

The script follows a config-first approach:

  • If a field is defined in pe.config.json, it will be used
  • If missing, the script will prompt for input at runtime

Supported fields:

  • booking.dateTarget
  • booking.courtPriority
  • booking.startHour
  • booking.waitUntil
  • booking.bookTwoSlots

booking.dateTarget supports weekday number 1-7, fixed date MM/DD, or special value next7d for today + 7 days.

booking.courtPriority supports either string form like "1,2,4" or array form like ["1", "2", "4"].

booking.startHour uses only the starting hour, such as 18, interpreted as 18:00. If booking.bookTwoSlots = true, the second slot is the following hour.

booking.waitUntil uses HH:mm:ss, such as 17:42:40.


Runtime Summary

Before entering the waiting phase, the script prints a booking summary:

Booking target: date=next7d, time=18:00, 19:00, courts=1号场, 2号场, 4号场

This helps verify configuration correctness before execution.


Additional Notes

  • The browser will not close automatically after submission
  • If booking fails, the browser remains open for inspection
  • Currently supports up to 2 consecutive hours
  • For consistent behavior across machines, install the Playwright browser in advance and use browser.mode: "playwright"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages