From 161e89c9557ec1ffb6f88971ddd422253be734da Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 19:25:46 +0200 Subject: [PATCH] Sort the by-hand list by the Watchlist's careers_opened_at and print the watch rating Co-Authored-By: Claude Sonnet 5.5 --- app/cli.py | 18 +++++++++++------- app/jobs/sources.py | 6 +++--- tests/test_sources.py | 24 ++++++++++++++---------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/cli.py b/app/cli.py index 35b3cbe..fe92c5d 100644 --- a/app/cli.py +++ b/app/cli.py @@ -409,12 +409,14 @@ def edit_company(store: Store, args: argparse.Namespace) -> int: def company_checked(store: Store, key: str) -> int: - """`app companies checked acme`: its careers page was looked at just now.""" + """`app companies checked acme`: its careers page was looked at just now, + which the Watchlist keeps as `careers_opened_at`, the same stamp opening + the page from there sets.""" if store.company(key) is None: print(f"companies checked: no company {key!r}", file=sys.stderr) return 1 - company = store.update_company(key, checked_at=store.now()) - print(json.dumps({"key": key, "checked_at": company.checked_at})) + company = store.update_company(key, careers_opened_at=store.now()) + print(json.dumps({"key": key, "careers_opened_at": company.careers_opened_at})) return 0 @@ -437,14 +439,16 @@ def remove_company(store: Store, key: str) -> int: def list_by_hand(store: Store) -> int: """`app companies by-hand`: the companies with no board shown that are not - known from a search only, one line each, never checked first and then the - longest ago, as the Sources page lists them; see `jobs.sources.by_hand`.""" + known from a search only, one line each, never opened first and then the + longest ago; `watch` is the Watchlist's rating, yes, no or a dash for + unrated. See `jobs.sources.by_hand`.""" from app import jobs rows = jobs.sources.by_hand(store) for c in rows: - checked = c.checked_at[:10] or "never" - print(f"{c.name:30} {c.hand_reason or '-':8} {checked:10} {c.careers_url}") + watch = "-" if c.watch is None else "yes" if c.watch else "no" + opened = c.careers_opened_at[:10] or "never" + print(f"{c.name:30} {c.hand_reason or '-':8} {watch:4} {opened:10} {c.careers_url}") print(f"{len(rows)} by hand") return 0 diff --git a/app/jobs/sources.py b/app/jobs/sources.py index 9e566b6..76ceb5e 100644 --- a/app/jobs/sources.py +++ b/app/jobs/sources.py @@ -169,13 +169,13 @@ def known_from_search_only(company: Company, ever_boarded: set[str]) -> bool: def by_hand(store: Store) -> list[Company]: """The list checked by hand: companies with no board shown that are not - known from a search only. Never checked first, then the longest ago; the - name breaks a tie.""" + known from a search only. Never opened first, then the longest ago + (`careers_opened_at`, the Watchlist's stamp); the name breaks a tie.""" boards = store.company_boards() ever_boarded = {company_key(s.company) for s in store.subscriptions(source="ats")} rows = [c for c in store.companies() if c.key not in boards and not known_from_search_only(c, ever_boarded)] - return sorted(rows, key=lambda c: (c.checked_at, c.name.casefold())) + return sorted(rows, key=lambda c: (c.careers_opened_at, c.name.casefold())) class Conflict(ValueError): diff --git a/tests/test_sources.py b/tests/test_sources.py index dfedad0..d98bced 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -373,14 +373,14 @@ def test_remove_company_refuses_a_board_shown_and_open_roles( sources.remove_company(store, "open") -def test_by_hand_lists_the_unboarded_never_checked_first( +def test_by_hand_lists_the_unboarded_never_opened_first( store: Store, boards: Boards) -> None: sources.add_by_hand(store, "Zeta") sources.add_by_hand(store, "Beta") sources.add_by_hand(store, "Old") sources.add_by_hand(store, "Recent") - store.update_company("old", checked_at="2026-08-01T00:00:00+00:00") - store.update_company("recent", checked_at="2026-09-20T00:00:00+00:00") + store.update_company("old", careers_opened_at="2026-08-01T00:00:00+00:00") + store.update_company("recent", careers_opened_at="2026-09-20T00:00:00+00:00") sources.set_board(store, "read", "greenhouse:acme", name="Read") # a board: not listed store.add_company("Pleo", key="pleo", ats="teamtailor") # unread, no reason: listed store.add_company("Quiet", key="quiet") # from a search only @@ -486,8 +486,8 @@ def test_cli_edit_checked_and_remove_a_company_by_hand( assert "no company 'nobody'" in capsys.readouterr().err assert _cli(tmp_path, "checked", "acme") == 0 - stamp = json.loads(capsys.readouterr().out)["checked_at"] - assert stamp and store.company("acme").checked_at == stamp # type: ignore[union-attr] + stamp = json.loads(capsys.readouterr().out)["careers_opened_at"] + assert stamp and store.company("acme").careers_opened_at == stamp # type: ignore[union-attr] assert _cli(tmp_path, "checked", "nobody") == 1 capsys.readouterr() @@ -499,20 +499,24 @@ def test_cli_edit_checked_and_remove_a_company_by_hand( assert _cli(tmp_path, "remove", "acme") == 1 -def test_cli_by_hand_prints_never_checked_first_then_the_oldest_check( +def test_cli_by_hand_prints_never_opened_first_then_the_oldest_and_the_watch_rating( store: Store, boards: Boards, tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None: store.add_company("Recent", careers_url="https://recent.example/jobs", - hand_reason="gone", checked_at="2026-09-20T08:00:00+00:00") - store.add_company("Old", hand_reason="robots", checked_at="2026-08-01T08:00:00+00:00") + hand_reason="gone") + store.add_company("Old", hand_reason="robots") store.add_company("Never", careers_url="https://never.example/jobs", hand_reason="added") + store.update_company("recent", careers_opened_at="2026-09-20T08:00:00+00:00", watch=0) + store.update_company("old", careers_opened_at="2026-08-01T08:00:00+00:00", watch=1) sources.set_board(store, "read", "greenhouse:acme", name="Read") assert _cli(tmp_path, "by-hand") == 0 lines = capsys.readouterr().out.splitlines() assert [ln.split()[0] for ln in lines[:-1]] == ["Never", "Old", "Recent"] - assert lines[0].split() == ["Never", "added", "never", "https://never.example/jobs"] - assert lines[1].split() == ["Old", "robots", "2026-08-01"] + assert lines[0].split() == ["Never", "added", "-", "never", "https://never.example/jobs"] + assert lines[1].split() == ["Old", "robots", "yes", "2026-08-01"] + assert lines[2].split() == ["Recent", "gone", "no", "2026-09-20", + "https://recent.example/jobs"] assert lines[-1] == "3 by hand"