Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,13 @@ Installing the library installs `themeparks-backfill`, which does all of the
above and stops before the walls:

```bash
# How far back it reaches is your plan, so set the key first: without one you get
# the 7 days anonymous access allows, and the run still succeeds, quietly.
export THEMEPARKS_API_KEY=tpw_your_key

themeparks-backfill "Disneyland Park" # a park, by name or id
themeparks-backfill "Walt Disney World Resort" # a destination: every park in it
themeparks-backfill --list disney # find an id. Needs no key.
themeparks-backfill --list disney # find an id. This part needs no key.
```

It reads how far back your own key may ask and starts there, writes NDJSON or
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/test_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,48 @@ class FakeEntity:
entityType = "ATTRACTION" # noqa: N815 - the API's own spelling

assert _ref(FakeEntity()).entity_type == "ATTRACTION"


class TestAnAnonymousRunSaysSoWhenItFinishes:
"""The warning at the START scrolls away. The last line must carry it too.

Running the documented example without a key succeeds: 433 rows of Magic
Kingdom instead of ~94,000, exit 0, and a file. A customer who has just paid
for 400 days has no reason to think anything went wrong -- the notice was
four lines printed before a run that takes minutes, and the last thing on
screen is "done: 433 rows".
"""

def _run(self, tmp_path: Path, argv: list[str], monkeypatch) -> None:
monkeypatch.setattr(backfill, "_catalogue", lambda tp: [("p", "Park", "d", "Dest")])
monkeypatch.setattr(backfill, "_run_all", lambda tp, targets, args: 0)
monkeypatch.setattr(backfill, "ThemeParks", lambda **kw: _NullClient())
backfill.main([*argv, "--out", str(tmp_path)])

def test_an_anonymous_run_says_so_at_the_end(self, tmp_path: Path, capsys, monkeypatch) -> None:
monkeypatch.delenv("THEMEPARKS_API_KEY", raising=False)
self._run(tmp_path, ["p"], monkeypatch)
err = capsys.readouterr().err
# Both ends: before, so it can be acted on, and after, so it is the last
# thing read.
assert err.count("7 days") >= 2
assert "ANONYMOUS ACCESS" in err
assert err.rstrip().endswith("keys: https://www.themeparks.wiki/profile")

def test_a_run_with_a_key_says_nothing_of_the_sort(
self, tmp_path: Path, capsys, monkeypatch
) -> None:
self._run(tmp_path, ["p", "--api-key", "tpw_test"], monkeypatch)
err = capsys.readouterr().err
assert "ANONYMOUS" not in err
assert "no API key" not in err


class _NullClient:
"""A client that is never actually used: _run_all is stubbed out."""

def __enter__(self):
return self

def __exit__(self, *_exc):
return False
20 changes: 19 additions & 1 deletion themeparks/backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,10 @@ def _print_list(catalogue: list[tuple[str, str, str, str]], needle: str | None)


EPILOG = """examples:
export THEMEPARKS_API_KEY=tpw_your_key
how far back this reaches is your plan, so without a key you get the 7
days anonymous access allows -- and the run still succeeds, quietly.

themeparks-backfill "Disneyland Park"
the whole daily history your plan reaches, as NDJSON, into the current
directory
Expand Down Expand Up @@ -1248,7 +1252,21 @@ def main(argv: list[str] | None = None) -> int:
file=sys.stderr,
)

return _run_all(tp, targets, args)
status = _run_all(tp, targets, args)
# SAID AGAIN AT THE END, and this is the point of it. The warning above
# is printed before a run that takes minutes, so it scrolls away, and the
# last thing on screen is "done: 433 rows" -- which for a customer who
# thought they were downloading five years is indistinguishable from
# success. They paid for 400 days and got seven, exit 0, no complaint.
if not args.api_key:
print(
"\nthat was ANONYMOUS ACCESS: the last 7 days only.\n"
" a free key reads 30 days, Pro 400, Business the whole archive\n"
" set THEMEPARKS_API_KEY and run the same command again\n"
" keys: https://www.themeparks.wiki/profile",
file=sys.stderr,
)
return status
return 0


Expand Down
Loading