feat: implement import-trips CLI with Playwright-based Kia trip scraper #2

Closed
noid wants to merge 2 commits from feat/import-trips into main
Owner

Implements the import-trips CLI command for scraping trip history from owners.kia.com.

Changes

  • New scripts/import_trips.py with full implementation
  • New tests/test_import_trips.py with 12 mock-based tests (no real API calls)
  • Added pytest and pytest-mock as dev dependencies

CLI Flags

  • --start YYYYMMDD (default: 30 days ago)
  • --end YYYYMMDD (default: today)
  • --dry-run (login only, skip trip fetch)
  • --verbose (debug logging)

Functional

  • Uses Playwright headless browser automation
  • Logs in with KIA_USERNAME/KIA_PASSWORD from .env
  • Intercepts the trip API POST to inject requested date range
  • Parses payload.tripInfo into clean snake_case JSON output
  • Handles auth failures gracefully (bad credentials, expired session)
  • Closes browser on exit via finally block

Testing

All 12 tests pass. Coverage includes:

  • CLI argument parsing (defaults, custom dates, flags)
  • Successful trip fetch and JSON schema validation
  • Dry-run mode
  • Auth failure paths
  • Browser lifecycle (close on success and error)
  • Trip endpoint interception

Verification

uv run pytest tests/test_import_trips.py -v

Closes #3

Implements the import-trips CLI command for scraping trip history from owners.kia.com. ## Changes - New `scripts/import_trips.py` with full implementation - New `tests/test_import_trips.py` with 12 mock-based tests (no real API calls) - Added pytest and pytest-mock as dev dependencies ## CLI Flags - `--start YYYYMMDD` (default: 30 days ago) - `--end YYYYMMDD` (default: today) - `--dry-run` (login only, skip trip fetch) - `--verbose` (debug logging) ## Functional - Uses Playwright headless browser automation - Logs in with KIA_USERNAME/KIA_PASSWORD from .env - Intercepts the trip API POST to inject requested date range - Parses payload.tripInfo into clean snake_case JSON output - Handles auth failures gracefully (bad credentials, expired session) - Closes browser on exit via finally block ## Testing All 12 tests pass. Coverage includes: - CLI argument parsing (defaults, custom dates, flags) - Successful trip fetch and JSON schema validation - Dry-run mode - Auth failure paths - Browser lifecycle (close on success and error) - Trip endpoint interception ## Verification ```bash uv run pytest tests/test_import_trips.py -v ``` Closes #3
Add 12 tests covering:
- CLI argument parsing (defaults, custom dates, --dry-run, --verbose)
- Successful trip fetch and JSON output schema
- Dry-run mode (login only, skip trip fetch)
- Auth failure paths (bad credentials, expired session)
- Browser lifecycle (close on success and error)
- Trip endpoint interception verification

All tests use mocked Playwright — no real API calls.
- Parse CLI args: --start, --end, --dry-run, --verbose
- Load KIA_USERNAME/KIA_PASSWORD from .env via python-dotenv
- Launch headless Chromium via Playwright to owners.kia.com
- Perform login and wait for dashboard confirmation
- Intercept trip API POST to inject requested date range
- Parse payload.tripInfo into clean snake_case JSON output
- Handle auth failures gracefully (bad credentials, expired session)
- Close browser in finally block (success or error)
- Doc comments on all public functions
noid closed this pull request 2026-07-28 03:07:19 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
noid/kia-dashboard!2
No description provided.