humble-bundle-keys 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. humble_bundle_keys-0.4.0/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
  2. humble_bundle_keys-0.4.0/.github/ISSUE_TEMPLATE/config.yml +8 -0
  3. humble_bundle_keys-0.4.0/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
  4. humble_bundle_keys-0.4.0/.github/ISSUE_TEMPLATE/selector_broken.md +50 -0
  5. humble_bundle_keys-0.4.0/.github/workflows/ci.yml +71 -0
  6. humble_bundle_keys-0.4.0/.github/workflows/release.yml +106 -0
  7. humble_bundle_keys-0.4.0/.gitignore +102 -0
  8. humble_bundle_keys-0.4.0/CHANGELOG.md +152 -0
  9. humble_bundle_keys-0.4.0/CONTRIBUTING.md +94 -0
  10. humble_bundle_keys-0.4.0/LICENSE +21 -0
  11. humble_bundle_keys-0.4.0/PKG-INFO +310 -0
  12. humble_bundle_keys-0.4.0/README.md +281 -0
  13. humble_bundle_keys-0.4.0/SECURITY.md +41 -0
  14. humble_bundle_keys-0.4.0/docs/ARCHITECTURE.md +153 -0
  15. humble_bundle_keys-0.4.0/docs/CHOICE_CLAIM_SPEC.md +319 -0
  16. humble_bundle_keys-0.4.0/docs/WHATS_CLAIMABLE.md +91 -0
  17. humble_bundle_keys-0.4.0/humble_bundle_keys/__init__.py +6 -0
  18. humble_bundle_keys-0.4.0/humble_bundle_keys/__main__.py +6 -0
  19. humble_bundle_keys-0.4.0/humble_bundle_keys/_browser_fetch.py +101 -0
  20. humble_bundle_keys-0.4.0/humble_bundle_keys/_orders_cache.py +125 -0
  21. humble_bundle_keys-0.4.0/humble_bundle_keys/api.py +432 -0
  22. humble_bundle_keys-0.4.0/humble_bundle_keys/auth.py +227 -0
  23. humble_bundle_keys-0.4.0/humble_bundle_keys/browser_choice.py +569 -0
  24. humble_bundle_keys-0.4.0/humble_bundle_keys/choice.py +466 -0
  25. humble_bundle_keys-0.4.0/humble_bundle_keys/cli.py +804 -0
  26. humble_bundle_keys-0.4.0/humble_bundle_keys/diagnose.py +610 -0
  27. humble_bundle_keys-0.4.0/humble_bundle_keys/exporter.py +125 -0
  28. humble_bundle_keys-0.4.0/humble_bundle_keys/models.py +62 -0
  29. humble_bundle_keys-0.4.0/humble_bundle_keys/scraper.py +582 -0
  30. humble_bundle_keys-0.4.0/pyproject.toml +62 -0
  31. humble_bundle_keys-0.4.0/tests/RUNBOOK.md +167 -0
  32. humble_bundle_keys-0.4.0/tests/__init__.py +0 -0
  33. humble_bundle_keys-0.4.0/tests/fixtures/choice_claim/README.md +26 -0
  34. humble_bundle_keys-0.4.0/tests/fixtures/choice_claim/analytics_get_game.json +29 -0
  35. humble_bundle_keys-0.4.0/tests/fixtures/choice_claim/analytics_tile_click.json +29 -0
  36. humble_bundle_keys-0.4.0/tests/fixtures/choice_claim/choosecontent_request_response.json +34 -0
  37. humble_bundle_keys-0.4.0/tests/fixtures/choice_claim/redeemkey_request_response.json +34 -0
  38. humble_bundle_keys-0.4.0/tests/test_api_parser.py +130 -0
  39. humble_bundle_keys-0.4.0/tests/test_browser_choice.py +126 -0
  40. humble_bundle_keys-0.4.0/tests/test_browser_fetch.py +100 -0
  41. humble_bundle_keys-0.4.0/tests/test_choice.py +318 -0
  42. humble_bundle_keys-0.4.0/tests/test_diagnose_sanitiser.py +229 -0
  43. humble_bundle_keys-0.4.0/tests/test_exporter.py +178 -0
  44. humble_bundle_keys-0.4.0/tests/test_parsers.py +52 -0
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report something that's broken (not a Humble redesign — see "Selector / DOM broken" for that)
4
+ title: '[bug] '
5
+ labels: bug
6
+ ---
7
+
8
+ ## What happened
9
+
10
+ <!-- One-sentence summary. -->
11
+
12
+ ## Steps to reproduce
13
+
14
+ ```bash
15
+ # The exact command(s) you ran:
16
+ humble-bundle-keys ...
17
+ ```
18
+
19
+ ## Expected behavior
20
+
21
+ <!-- What you thought would happen. -->
22
+
23
+ ## Actual behavior
24
+
25
+ <!-- Logs, error messages, summary table contents. Paste from the run log if useful. -->
26
+
27
+ ## Environment
28
+
29
+ - OS: <!-- macOS 14 / Ubuntu 22.04 / Windows 11 etc. -->
30
+ - Python: <!-- output of `python --version` -->
31
+ - humble-bundle-keys version: <!-- output of `humble-bundle-keys --version` -->
32
+ - Account type: <!-- Choice subscriber? Past-Monthly subscriber? Free user? -->
33
+
34
+ ## Run log
35
+
36
+ <!-- The auto-generated run log lives at ~/.humble-bundle-keys/runs/run-<timestamp>.log
37
+ Attach the relevant one (or paste excerpts).
38
+ IMPORTANT: scan it before attaching — even though we redact known-sensitive
39
+ headers in diagnose bundles, the standard run log captures real key values.
40
+ If you paste keys, redact them first. -->
@@ -0,0 +1,8 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Security issue (do not file publicly)
4
+ url: https://github.com/gfargo/humble-bundle-keys/blob/main/SECURITY.md
5
+ about: Vulnerabilities should be emailed to the maintainer instead of filed as a public issue.
6
+ - name: How to capture a diagnose bundle
7
+ url: https://github.com/gfargo/humble-bundle-keys/blob/main/CONTRIBUTING.md#filing-a-selector-broken-bug
8
+ about: Step-by-step for the sanitized debug bundle that 90% of bug reports need.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest something the tool could do
4
+ title: '[feature] '
5
+ labels: enhancement
6
+ ---
7
+
8
+ ## What's the use case
9
+
10
+ <!-- Describe the situation where you want this. Concrete > abstract. -->
11
+
12
+ ## What you'd want to type
13
+
14
+ ```bash
15
+ # Example: a new flag, a new subcommand, a new output format
16
+ humble-bundle-keys --some-new-thing
17
+ ```
18
+
19
+ ## Why the tool can't already do it
20
+
21
+ <!-- If you know — e.g. "the API doesn't expose this" or "there's no entry point for it". -->
22
+
23
+ ## Notes
24
+
25
+ <!-- Anything else: similar tools that do this, screenshots of the UI, etc. -->
@@ -0,0 +1,50 @@
1
+ ---
2
+ name: Selector / DOM broken
3
+ about: Humble redesigned something and the tool stopped finding rows / cards / buttons
4
+ title: '[selector] '
5
+ labels: bug, selectors
6
+ ---
7
+
8
+ ## Symptom
9
+
10
+ <!-- Choose one:
11
+ - 0 rows found on /home/keys
12
+ - 0 cards found on /membership/<slug>
13
+ - "Get Game on Steam" button not visible
14
+ - Key field never populated within timeout
15
+ - Other (describe) -->
16
+
17
+ ## Date you noticed it
18
+
19
+ <!-- Approximate. Helps correlate with Humble's redesign cadence. -->
20
+
21
+ ## Diagnose bundle
22
+
23
+ The fastest path to a fix is a sanitized diagnose bundle. **Run one of these** depending on what's broken:
24
+
25
+ ```bash
26
+ # /home/keys regression:
27
+ humble-bundle-keys diagnose -v
28
+
29
+ # /membership/<slug> regression:
30
+ humble-bundle-keys diagnose --membership-page <some-month-slug> -v
31
+ ```
32
+
33
+ This produces `humble-diagnose/diagnose-<timestamp>/safe-to-share.zip`.
34
+
35
+ **Before attaching, spot-check the zip:**
36
+
37
+ - Open a couple of the JSON files in `api/`. Real keys (anything looking like `XXXXX-XXXXX-XXXXX`) should appear as `REDACTED-KEY`.
38
+ - Check email addresses appear as `REDACTED@example.com`.
39
+ - Check `?gamekey=` URL params appear as `?gamekey=REDACTED-GAMEKEY`.
40
+ - Check `Cookie` and `Authorization` headers are not present in the JSON header dumps.
41
+
42
+ If any sensitive value slipped through, **don't attach** — open a [security issue](../SECURITY.md) instead.
43
+
44
+ ## Attached bundle
45
+
46
+ <!-- Drag-and-drop your safe-to-share.zip here, or link to a paste/gist. -->
47
+
48
+ ## Anything else
49
+
50
+ <!-- Custom flags you're using? Particular months that fail vs. work? Account quirks? -->
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ name: test (py${{ matrix.python-version }})
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.10", "3.11", "3.12"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Set up Python ${{ matrix.python-version }}
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+ cache: pip
29
+
30
+ - name: Install package + dev deps
31
+ run: |
32
+ python -m pip install --upgrade pip
33
+ pip install -e .[dev]
34
+
35
+ - name: Lint with ruff
36
+ run: ruff check humble_bundle_keys tests
37
+
38
+ - name: Run tests
39
+ # Tests don't need Playwright browsers because none of them spin up
40
+ # a real browser (they're all parser / sanitiser unit tests). If we
41
+ # later add browser-dependent tests, they should be marked `live`
42
+ # and excluded from CI.
43
+ run: pytest -q tests/
44
+
45
+ build:
46
+ name: build sdist + wheel
47
+ runs-on: ubuntu-latest
48
+ needs: test
49
+ steps:
50
+ - uses: actions/checkout@v4
51
+
52
+ - uses: actions/setup-python@v5
53
+ with:
54
+ python-version: "3.12"
55
+
56
+ - name: Install build
57
+ run: pip install build
58
+
59
+ - name: Build distributions
60
+ run: python -m build
61
+
62
+ - name: Sanity-check the wheel
63
+ run: |
64
+ pip install dist/*.whl
65
+ humble-bundle-keys --version
66
+
67
+ - name: Upload artifacts
68
+ uses: actions/upload-artifact@v4
69
+ with:
70
+ name: dist
71
+ path: dist/
@@ -0,0 +1,106 @@
1
+ name: Release
2
+
3
+ # Triggered by pushing a tag like v0.1.0
4
+ on:
5
+ push:
6
+ tags:
7
+ - "v*.*.*"
8
+
9
+ # PyPI trusted publishing requires id-token write.
10
+ # contents:write lets us create a GitHub Release.
11
+ permissions:
12
+ contents: write
13
+ id-token: write
14
+
15
+ jobs:
16
+ build:
17
+ name: Build sdist + wheel
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - uses: actions/setup-python@v5
23
+ with:
24
+ python-version: "3.12"
25
+
26
+ - name: Verify tag matches package version
27
+ run: |
28
+ tag="${GITHUB_REF#refs/tags/v}"
29
+ pkg=$(python -c "import tomllib,sys;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
30
+ echo "tag=$tag pkg=$pkg"
31
+ if [ "$tag" != "$pkg" ]; then
32
+ echo "::error::Tag v$tag does not match pyproject.toml version $pkg"
33
+ exit 1
34
+ fi
35
+
36
+ - name: Install build
37
+ run: pip install build
38
+
39
+ - name: Build
40
+ run: python -m build
41
+
42
+ - name: Smoke test the wheel
43
+ run: |
44
+ pip install dist/*.whl
45
+ humble-bundle-keys --version
46
+ humble-bundle-keys --help > /dev/null
47
+
48
+ - name: Upload artifacts
49
+ uses: actions/upload-artifact@v4
50
+ with:
51
+ name: dist
52
+ path: dist/
53
+
54
+ publish-pypi:
55
+ name: Publish to PyPI
56
+ needs: build
57
+ runs-on: ubuntu-latest
58
+ # https://docs.pypi.org/trusted-publishers/
59
+ environment:
60
+ name: pypi
61
+ url: https://pypi.org/p/humble-bundle-keys
62
+ permissions:
63
+ id-token: write
64
+ steps:
65
+ - uses: actions/download-artifact@v4
66
+ with:
67
+ name: dist
68
+ path: dist/
69
+
70
+ - uses: pypa/gh-action-pypi-publish@release/v1
71
+
72
+ github-release:
73
+ name: Create GitHub Release
74
+ needs: [build, publish-pypi]
75
+ runs-on: ubuntu-latest
76
+ permissions:
77
+ contents: write
78
+ steps:
79
+ - uses: actions/checkout@v4
80
+
81
+ - uses: actions/download-artifact@v4
82
+ with:
83
+ name: dist
84
+ path: dist/
85
+
86
+ - name: Extract release notes from CHANGELOG
87
+ id: notes
88
+ run: |
89
+ tag="${GITHUB_REF#refs/tags/v}"
90
+ if [ -f CHANGELOG.md ]; then
91
+ awk -v ver="$tag" '
92
+ /^## \[?[0-9]+\.[0-9]+\.[0-9]+\]?/ {
93
+ if (found) exit;
94
+ if (index($0, ver)) { found=1; next }
95
+ }
96
+ found { print }
97
+ ' CHANGELOG.md > release-notes.md
98
+ else
99
+ echo "Release v$tag" > release-notes.md
100
+ fi
101
+
102
+ - uses: softprops/action-gh-release@v2
103
+ with:
104
+ files: dist/*
105
+ body_path: release-notes.md
106
+ generate_release_notes: true
@@ -0,0 +1,102 @@
1
+ # =====================================================================
2
+ # humble-bundle-keys .gitignore
3
+ #
4
+ # Anything that could leak a real Steam key, an auth token, an order
5
+ # gamekey, or PII MUST be excluded here. We've had a lot of those file
6
+ # shapes appear during development. Be paranoid — a single committed
7
+ # diagnose-raw/ folder would expose every revealed key the user has.
8
+ # =====================================================================
9
+
10
+ # --- Python build/runtime artefacts ----------------------------------
11
+ __pycache__/
12
+ *.py[cod]
13
+ *$py.class
14
+ *.so
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # --- Virtualenvs ------------------------------------------------------
34
+ .venv/
35
+ venv/
36
+ env/
37
+ ENV/
38
+
39
+ # --- Editors / OS -----------------------------------------------------
40
+ .vscode/
41
+ .idea/
42
+ *.swp
43
+ *.swo
44
+ .DS_Store
45
+ Thumbs.db
46
+
47
+ # --- Test artefacts ---------------------------------------------------
48
+ .pytest_cache/
49
+ .ruff_cache/
50
+ .mypy_cache/
51
+ htmlcov/
52
+ .coverage
53
+ coverage.xml
54
+
55
+ # =====================================================================
56
+ # SECRETS / SENSITIVE DATA — NEVER COMMIT
57
+ # =====================================================================
58
+
59
+ # Persisted Humble session — has an authenticated _simpleauth_sess cookie
60
+ storage_state.json
61
+ .humble-bundle-keys/
62
+ .humble-keys/ # legacy name from pre-0.4.0
63
+
64
+ # Output CSVs contain the user's real keys
65
+ *.csv
66
+ !examples/*.csv # tiny sanitized example, if we ship one
67
+
68
+ # Diagnose bundles. The whole `humble-diagnose/` tree gets created by
69
+ # `humble-bundle-keys diagnose` and the raw/ subfolder explicitly contains
70
+ # real keys — we sanitize into safe-to-share/ but the raw/ side stays.
71
+ # Just exclude the whole top-level directory; users can attach
72
+ # safe-to-share.zip to issues without committing anything.
73
+ humble-diagnose/
74
+
75
+ # Order cache — contains full order JSON including some user metadata
76
+ orders-cache/
77
+
78
+ # Run logs — auto-written to ~/.humble-bundle-keys/runs/, but if a user
79
+ # moves them into the repo or uses --log-file inside the repo, exclude.
80
+ *.log
81
+ runs/
82
+
83
+ # Debug screenshots / HTML dumps from --debug-dir
84
+ Screenshot*.png
85
+ screenshot-*.png
86
+ debug-*.png
87
+ debug-*.html
88
+ debug/
89
+ trace-*.zip
90
+ trace.zip
91
+
92
+ # Dev-time downloaded captures (any .png at the repo root is suspect)
93
+ /Screenshot*.png
94
+
95
+ # Anything beginning with `MY_` is by convention personal scratch
96
+ MY_*
97
+
98
+ # .env files (we don't currently use any, but defence in depth — these
99
+ # are conventionally where folks put HUMBLE_SESSION_COOKIE)
100
+ .env
101
+ .env.*
102
+ !.env.example
@@ -0,0 +1,152 @@
1
+ # Changelog
2
+
3
+ All notable changes to `humble-bundle-keys` will be documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.4.0] — Public release
9
+
10
+ ### Changed
11
+ - **Renamed package and CLI from `humble-keys` to `humble-bundle-keys`** for discoverability. Repo: `github.com/gfargo/humble-bundle-keys`. PyPI: `humble-bundle-keys`. Python module: `humble_bundle_keys`. Trademark-respectful framing: clear "not affiliated with Humble Bundle" disclaimer in README.
12
+ - README rewritten end-to-end for 0.4.0 reality — covers all three modes (default reveal / `--claim-choice` / `--browser-claim`), the order cache, run logging, the silent-no-key categorization, and what's structurally claimable vs not.
13
+ - Pyproject URLs updated to point at the new repo, plus added `Repository` and `Changelog` URLs.
14
+
15
+ ### Added
16
+ - `.gitignore` hardened against accidental leaks: `humble-diagnose/`, `orders-cache/`, `runs/`, `.env*`, `*.log`, debug screenshots, anything `MY_*`. Existing ignores kept (storage_state.json, *.csv, etc.) and migrated to the new `~/.humble-bundle-keys/` directory while preserving legacy `~/.humble-keys/` for in-flight users.
17
+ - `CONTRIBUTING.md`, `SECURITY.md`, GitHub issue templates.
18
+ - `docs/ARCHITECTURE.md` and `docs/WHATS_CLAIMABLE.md`.
19
+
20
+ ## [0.3.5] — Run log files
21
+
22
+ ### Added
23
+ - All runs now auto-write a full DEBUG-level log to `~/.humble-bundle-keys/runs/run-<timestamp>.log` with last-20 retention. `--log-file PATH` overrides; `--no-log-file` disables. Console verbosity (`-v`/`-vv`) is decoupled from on-disk capture.
24
+ - Summary now prints the log path so it's discoverable without `-v`.
25
+
26
+ ## [0.3.4] — Browser-claim wait fix + skip expired
27
+
28
+ ### Fixed
29
+ - **Wait loop no longer breaks early on the "claimed" banner.** That signal fires ~1s after the click, but Humble's backend takes another 5–15s to write the actual key. We now poll the keyfield until either we get a real `XXXXX-XXXXX-XXXXX` string or hit the timeout — no shortcuts.
30
+ - **Pre-click detection of `.expired` keyfields.** Subscription-trial entries (IGN Plus, Boot.dev) have `class="js-keyfield keyfield expired"` and a "This key has expired" placeholder. Clicking them does nothing. We now skip them cleanly instead of burning the full timeout per game.
31
+ - Default `key_wait_ms` bumped from 20s to 30s for slow Humble responses on top-tier titles.
32
+
33
+ ## [0.3.3] — Browser-claim DOM selectors
34
+
35
+ ### Fixed
36
+ - **Modal selectors now match Humble's actual DOM.** Previous versions assumed a `<button>` for "Get Game on Steam" — the real element is a `<div class="js-keyfield keyfield enabled">` styled as a button. The same `.keyfield-value` div holds both the placeholder ("Get game on Steam") and the post-claim key, with parent `.redeemed` class as the discriminator.
37
+ - `_extract_key` now strictly requires `KEY_PATTERN` match and explicitly rejects the placeholder strings — fixes the bug where the button label was being saved as a "key" in the CSV.
38
+
39
+ ## [0.3.2] — Click-target tightening
40
+
41
+ ### Fixed
42
+ - Replaced `*:has-text('GET GAME ON STEAM')` with role-restricted selectors (`button.button-v2`, `button`, `a.button-v2`, `a`). The wildcard fallback was matching the modal wrapper itself; clicking it hit the backdrop and closed the modal instead of triggering the claim.
43
+ - `_extract_key` no longer falls back to "any short text" when no match is found — fixes the bug where empty modals returned the button label as a "key".
44
+
45
+ ## [0.3.1] — Order cache + browser-claim hardening
46
+
47
+ ### Added
48
+ - **Per-order JSON cache** at `~/.humble-bundle-keys/orders-cache/<gamekey>.json` with default 6h TTL. Cuts a warm run from ~2 minutes to ~10 seconds. Auto-invalidates after a successful reveal so the next run picks up new keys. CLI: `--no-cache`, `--cache-ttl-h N`, `--clear-cache`.
49
+
50
+ ### Fixed
51
+ - `BrowserChoiceClaimer` post-click wait scoped to the just-opened modal instead of the page. Prevents stale `.keyfield-value` elements from already-claimed cards on the same page from short-circuiting the wait.
52
+ - Anchor pages in both `ApiScraper` and `ChoiceClaimer` self-heal if they drift off-origin (auth-refresh redirect etc.).
53
+ - Dry-run skips no longer counted as failures in the summary.
54
+
55
+ ## [0.3.0] — Browser-driven Choice claim
56
+
57
+ ### Added
58
+ - **`--browser-claim`** — drives the actual `/membership/<slug>` membership pages in Chromium. For each Choice/Monthly month with unclaimed games, finds each card on the page, clicks "GET GAME ON STEAM" in the modal, waits for Humble to allocate the key, extracts it. Catches the cases the API path can't see (legacy "pick N of M" months where unselected games never appear in your order JSON).
59
+ - **`--membership-only SLUG`** — restrict `--browser-claim` to one membership page. Useful for testing.
60
+ - New module `humble_bundle_keys.browser_choice` with `BrowserChoiceClaimer`, `derive_membership_slug`, plus DOM-selector constants derived from a captured diagnose bundle.
61
+
62
+ ## [0.2.7] — Choice typo + categorization
63
+
64
+ ### Fixed
65
+ - Choice keytype regex now matches Humble's real-world `_hoice_` typo (e.g. `road96_europe_hoice_steam` is genuinely missing a `c`).
66
+
67
+ ### Added
68
+ - `categorize_keytype()` — labels each silent-no-key tpk as one of `choice` / `monthly` / `freegame` / `keyless` / `softwarebundle` / `voucher` / `bundle` / `other` so the run summary tells users at a glance which holdouts are recoverable vs structurally manual.
69
+
70
+ ## [0.2.6] — Silent-no-key diagnostics
71
+
72
+ ### Added
73
+ - Run summary now lists each silent-no-key tpk's title + `tpk.machine_name` + `order.machine_name` (first 10 shown, ellipsis for the rest). Makes it possible to refine pattern detection without a full diagnose run.
74
+
75
+ ## [0.2.5] — Auto-headed for reveals + anchor-page healing + silent-no-key signal
76
+
77
+ ### Fixed
78
+ - **Anchor page heals when navigation context is lost.** A run that worked otherwise had one entry fail with `Page.evaluate: Execution context was destroyed, most likely because of a navigation`. Both `ApiScraper._get_anchor_page` and `ChoiceClaimer._get_anchor_page` now check the page's URL each call, re-navigate to humblebundle.com if it's drifted off-origin, and fall back to a fresh page if re-navigation fails.
79
+
80
+ ### Changed
81
+ - **`humble-bundle-keys` now auto-flips to `--no-headless` when the run will mutate state** (i.e. `--reveal` and/or `--claim-choice`, when not in `--dry-run`). Verified via 0.2.4: `--headless` produces 0 reveals and 167 Cloudflare 403s; `--no-headless` produces 144 reveals and 2 errors. The fix is structural — Cloudflare's bot management rejects state-changing POSTs from headless Chromium even when the SPA itself works fine. Users who really want headless can pass `--no-reveal --dry-run` together.
82
+
83
+ ### Added
84
+ - New stat `keys_silent_no_response` — counts reveal calls that returned 2xx but didn't yield a key. The summary surfaces them with a hint that those are likely Humble Choice subscription games that need the two-step `--claim-choice` flow rather than the direct redeemkey path.
85
+
86
+ ## [0.2.4] — Bypass Cloudflare bot detection on POSTs
87
+
88
+ ### Fixed
89
+ - **All `/humbler/redeemkey` and `/humbler/choosecontent` POSTs were being 403'd by Cloudflare.** Cloudflare fingerprints incoming HTTP/2 + TLS handshakes and was flagging Playwright's `APIRequestContext` as bot traffic. We now route POSTs through the actual browser via `page.evaluate("fetch(...)")` — Cloudflare sees a real Chrome request from the same origin with normal cookies, lets it through. GETs continue to use `APIRequestContext` since they don't trigger the challenge. Diagnosed from a 0.2.3 run that returned `<!DOCTYPE html>... <html class="no-js ie6 oldie">` (the Cloudflare challenge template) on every reveal attempt.
90
+ - New module `humble_bundle_keys._browser_fetch` with a single helper `post_form_in_browser(page, url, body, ...)` shared between `ApiScraper` and `ChoiceClaimer`.
91
+ - Both scrapers now lazily open an "anchor page" navigated to humblebundle.com on first POST, and close it when scraping ends.
92
+
93
+ ### Added
94
+ - 6 tests in `tests/test_browser_fetch.py` for the JS payload shape, header construction, and 4xx response handling.
95
+
96
+ ## [0.2.3] — Surface reveal errors
97
+
98
+ ### Improved
99
+ - Reveal errors are now logged at WARNING level (so `-v` exposes them) and the run summary prints the first 5 errors verbatim. Previously the count was visible but the messages required a re-run.
100
+
101
+ ## [0.2.2] — Reveal headers + stable merge identity
102
+
103
+ ### Fixed
104
+ - **`api.py::_reveal` now sends the same headers Humble's frontend uses** for `/humbler/redeemkey` calls: `X-Requested-With: XMLHttpRequest`, `Accept: application/json, text/javascript, */*; q=0.01`, and `Referer: https://www.humblebundle.com/home/keys`. Without `X-Requested-With`, Humble's backend appears to reject the call (acts as a soft anti-CSRF check). Fixes 0.2.1's "0 keys revealed, 167 errors" symptom — we were now making the calls (post-keyindex-fix) but they were being rejected.
105
+ - **`exporter.merge_with_existing` now uses a stable identity** (`humble_url` + `game_title` + `platform`) instead of `(game_title, bundle_name, platform)`. Earlier versions extracted `bundle_name` from the wrong API field, leaving it blank in older CSVs; merging an old CSV with a freshly-extracted run was producing duplicate rows when the bundle_name went from "" to (e.g.) "August 2019 Humble Monthly". Existing rows now collapse correctly even when the bundle_name was blank.
106
+
107
+ ### Improved
108
+ - 4XX responses from `/humbler/redeemkey` now include up to 200 chars of the response body in the error message — surfaces server-provided rejection reasons in the run summary.
109
+
110
+ ## [0.2.1] — Critical reveal fix
111
+
112
+ ### Fixed
113
+ - **`humble_bundle_keys.api.ApiScraper._reveal` now uses the correct field name** for `keyindex` on order tpks. Humble's API uses `keyindex` (one word); we were reading `key_index` (with underscore), which always returned `None`, causing the precondition to silently bail on every single unclaimed tpk. Verified against captured production data: the old code would have called `/humbler/redeemkey` for 0 of 167 unclaimed tpks; the new code will call it for all 167. **This is why prior runs reported "0 keys revealed" despite many unclaimed games.**
114
+ - `humble_bundle_keys.choice.ChoiceClaimer.claim_one` had the same bug; also fixed.
115
+ - `humble_bundle_keys.api._extract_tpk` now reads `bundle_name` from the actual location (`order.product.machine_name` / `order.product.human_name`) instead of the root level, where those fields don't exist. Falls back to root for tolerance.
116
+ - `humble_bundle_keys.choice.looks_like_choice_order` now reads `product.category=="subscriptioncontent"` and `product.machine_name` (the real shape) instead of the root, and explicitly rejects legacy Humble Monthly orders (those use Flow A directly, not the two-step claim).
117
+
118
+ ### Changed
119
+ - Broadened the Choice keytype regex to match all observed real-world patterns: `_choice_steam` (no modifier), `_row_choice_steam`, `_naeu_choice_steam` (regional), `_choice_epic_keyless` (multi-word platform). Previously only matched `_row_choice_<word>`.
120
+
121
+ ## [0.2.0] — Humble Choice claim support
122
+
123
+ ### Added
124
+ - **`--claim-choice` flag** — drives the two-step `POST /humbler/choosecontent` + `POST /humbler/redeemkey` flow that Humble's frontend uses behind "GET GAME ON STEAM" on `/membership/<month>` pages. Off by default. Includes `--max-claims` (default 25), `--claim-delay-s` (default 3.0), and a `--yes` confirmation skip for non-interactive use. See `docs/CHOICE_CLAIM_SPEC.md` for the discovered API contract.
125
+ - New module `humble_bundle_keys.choice` with the `ChoiceClaimer` class plus pure helpers (`is_choice_keytype`, `short_id_for_keytype`, `looks_like_choice_order`, `unclaimed_choice_tpks`, `build_choosecontent_body`, `build_redeemkey_body`, `extract_revealed_key`).
126
+ - `humble-bundle-keys diagnose --membership-page <slug>` — captures sanitised diagnostic artifacts of the Choice page interaction, with PII / keys / session tokens redacted. Reuses the existing browser window and supports an Enter-to-stop completion signal in the terminal.
127
+ - Diagnose XHR capture broadened to all of `humblebundle.com` (excluding static assets), and now records request method, headers, and body alongside the response. Sensitive headers (Cookie, Set-Cookie, Authorization, CSRF-Prevention-Token, X-CSRF-Token, X-XSRF-Token) are stripped before write.
128
+ - `tests/fixtures/choice_claim/` — sanitised live captures of the four wire calls behind one "GET GAME ON STEAM" click, used as test fixtures.
129
+ - 17 new tests (8 redaction + 9 Choice-flow) on top of the existing 39.
130
+
131
+ ### Changed
132
+ - `ApiScraper` now exposes a `.orders` list of fetched order JSON blobs so the Choice claim phase can reuse them without re-fetching.
133
+ - `_run_scraper` returns a 3-tuple `(rows, stats, api_or_none)` so callers can chain into the Choice claim phase.
134
+
135
+ ### Fixed
136
+ - `humble-bundle-keys diagnose --membership-page` previously opened a second browser window and could miss a closed-tab event. Now reuses the existing page (one window only) and adds an Enter-to-stop signal as the primary completion path.
137
+
138
+ ## [0.1.0] — initial release
139
+
140
+ ### Added
141
+ - Initial release.
142
+ - Persisted-session auth: first run opens a real browser for login, subsequent runs are headless.
143
+ - `HUMBLE_SESSION_COOKIE` env-var auth as a CI-friendly alternative.
144
+ - DOM scraper with multiple selector fallbacks for resilience.
145
+ - JSON API scraper using Humble's private `/api/v1/order` endpoints.
146
+ - `--scraper {auto,api,dom}` flag — `auto` tries the API first and falls back to DOM if the response shape is unrecognised.
147
+ - `humble-bundle-keys diagnose` subcommand: read-only capture run that produces a sanitised `safe-to-share.zip` for debugging selector or API drift, with PII stripped (keys → `REDACTED-KEY`, emails → `REDACTED@example.com`, gamekey URL params → `REDACTED-GAMEKEY`).
148
+ - `humble-bundle-keys logout` subcommand: deletes the saved session.
149
+ - `--merge` mode preserves keys revealed in previous runs even if a fresh extract misses them.
150
+ - Rich CSV output: `game_title, platform, key, bundle_name, bundle_date, redemption_deadline, redeemed_on_humble, os_support, humble_url`.
151
+ - 39 unit tests covering parsers, exporter, API parsing, and the diagnose sanitiser.
152
+ - CI workflow on Python 3.10/3.11/3.12; release workflow with PyPI trusted publishing.
@@ -0,0 +1,94 @@
1
+ # Contributing
2
+
3
+ Thanks for poking at this project. The most fragile parts of `humble-bundle-keys` are the DOM selectors (`humble_bundle_keys/scraper.py`, `humble_bundle_keys/browser_choice.py`) and the assumed shapes of Humble's undocumented JSON API (`humble_bundle_keys/api.py`). Both will eventually break when Humble redesigns something. The fastest path to a fix in those cases is a captured **diagnose bundle**, described below.
4
+
5
+ ## Dev setup
6
+
7
+ ```bash
8
+ git clone https://github.com/gfargo/humble-bundle-keys.git
9
+ cd humble-bundle-keys
10
+
11
+ # Using uv (recommended):
12
+ uv venv && source .venv/bin/activate
13
+ uv pip install -e ".[dev]"
14
+
15
+ # Or plain pip:
16
+ python3 -m venv .venv && source .venv/bin/activate
17
+ pip install -e ".[dev]"
18
+
19
+ # Browser engine (Playwright handles this for you):
20
+ playwright install chromium
21
+ ```
22
+
23
+ ## Running tests + lint
24
+
25
+ ```bash
26
+ # 121+ unit tests — should run in well under a second.
27
+ pytest
28
+
29
+ # Lint
30
+ ruff check humble_bundle_keys tests
31
+
32
+ # Lint with autofix
33
+ ruff check --fix humble_bundle_keys tests
34
+ ```
35
+
36
+ There are no live-account tests in CI — every test in `tests/` runs without a network or browser. Tests that genuinely need a real Humble account should be marked `@pytest.mark.live` and excluded from the default `pytest` run.
37
+
38
+ ## Filing a "selector broken" bug
39
+
40
+ If the tool stops finding rows / cards / buttons after a Humble redesign, the most useful thing you can attach is a sanitized diagnose bundle. Run:
41
+
42
+ ```bash
43
+ # For /home/keys regressions:
44
+ humble-bundle-keys diagnose -v
45
+
46
+ # For /membership/<slug> regressions:
47
+ humble-bundle-keys diagnose --membership-page <some-month-slug> -v
48
+ ```
49
+
50
+ This produces a `humble-diagnose/diagnose-<timestamp>/` directory with:
51
+
52
+ - `raw/` — contains your real keys. **Do NOT share.** Local debugging only.
53
+ - `safe-to-share/` — sanitized: keys → `REDACTED-KEY`, emails → `REDACTED@example.com`, gamekey URL params → `REDACTED-GAMEKEY`, auth headers stripped.
54
+ - `safe-to-share.zip` — convenience zip of the safe folder.
55
+
56
+ Spot-check the sanitized files (open a few of the JSON / HTML files and confirm no `XXXXX-XXXXX-XXXXX`-shaped strings or @ characters remain), then attach `safe-to-share.zip` to the GitHub issue.
57
+
58
+ The sanitizer has 14 unit tests covering every category we know about. If you find something it missed, that's itself a bug worth filing — check `humble_bundle_keys/diagnose.py` and `tests/test_diagnose_sanitiser.py`.
59
+
60
+ ## Filing a "Humble Choice month X has unclaimed games we can't see" bug
61
+
62
+ If `--browser-claim` is reporting `0 cards found` on a month you know has unclaimed games, please attach:
63
+
64
+ 1. The output of `humble-bundle-keys --browser-claim --dry-run --membership-only <slug> -vv`
65
+ 2. A `humble-bundle-keys diagnose --membership-page <slug>` bundle
66
+
67
+ ## Adding tests when you change a selector
68
+
69
+ If you fix a selector and have access to a fresh diagnose bundle:
70
+
71
+ 1. Drop the relevant `safe-to-share/membership/01-initial.html` into `tests/fixtures/<topic>/<name>.html`.
72
+ 2. Add a fixture-based test that loads the file via `page.set_content(...)` (or BeautifulSoup if you can avoid Playwright entirely) and asserts the new selector matches.
73
+
74
+ Pure parsing helpers (in `_extract_tpk`, `categorize_keytype`, `derive_membership_slug`, etc.) should always have direct unit tests — they're the cheapest layer to test.
75
+
76
+ ## PR conventions
77
+
78
+ - Bump `version` in both `pyproject.toml` and `humble_bundle_keys/__init__.py`. The release workflow checks they match.
79
+ - Add a `CHANGELOG.md` entry under a new version heading. Keep tone consistent with existing entries: explain the *user-visible* change, not the implementation, plus what symptom this fixes if it's a bug.
80
+ - Run `ruff check humble_bundle_keys tests` and `pytest` before pushing.
81
+
82
+ ## Releasing
83
+
84
+ Tag-driven via `.github/workflows/release.yml`:
85
+
86
+ ```bash
87
+ # After merging the version bump:
88
+ git tag v0.4.0
89
+ git push origin v0.4.0
90
+ ```
91
+
92
+ That triggers: build sdist + wheel → smoke-test the wheel → publish to PyPI via trusted publishing → create a GitHub Release with the wheel attached and notes pulled from CHANGELOG.md.
93
+
94
+ PyPI publishing uses [trusted publishing](https://docs.pypi.org/trusted-publishers/) — no API tokens stored as secrets. The `pypi` environment in the workflow corresponds to the `pypi.org/p/humble-bundle-keys` project's trusted-publishing config.