From dc881ad1a1983fcb4d4d47590836eb14de324c22 Mon Sep 17 00:00:00 2001 From: Lubai <1174273035@qq.com> Date: Thu, 5 Nov 2026 17:30:14 +0800 Subject: [PATCH] Add CLI command to list due follow-ups --- README.md | 1 + leadhound/cli.py | 21 ++++++++++++++++++++- tests/test_app.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf6a753..e659570 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ Cloud mode is password-protected and rate-limits sign-in attempts (5 wrong passw leadhound scan # search all sources leadhound local "Lisbon, Portugal" --category cafe,dentist --radius 0 --website no leadhound list --min-score 60 +leadhound followups # leads with a follow-up due, oldest first leadhound draft 12 # message in the lead's language leadhound audit https://example.com --booking leadhound shortcut # desktop icon diff --git a/leadhound/cli.py b/leadhound/cli.py index 00a4de3..838708f 100644 --- a/leadhound/cli.py +++ b/leadhound/cli.py @@ -75,11 +75,28 @@ def cmd_list(a, cfg): if not leads: print("no leads. Run: leadhound scan or leadhound local \"\"") return 0 + _print_leads(leads) + return 0 + + +def cmd_followups(a, cfg): + store = Store(a.db) + try: + leads = [lead for lead, _ in store.followups_due(cfg.follow_up_days, cfg.follow_up_max)] + finally: + store.close() + if not leads: + print("no follow-ups due") + return 0 + _print_leads(leads) + return 0 + + +def _print_leads(leads): print(f"{'id':>5} {'score':>5} {'age':>4} {'src':<7} {'status':<11} title") for l in leads: extra = f" [{l.budget}]" if l.budget else "" print(f"{l.id:>5} {l.score:>5} {_age(l.created_at):>4} {l.source:<7} {l.status:<11} {l.title[:70]}{extra}") - return 0 def cmd_show(a, cfg): @@ -272,6 +289,8 @@ def build_parser() -> argparse.ArgumentParser: p.add_argument("--limit", type=int, default=30) p.set_defaults(fn=cmd_list) + sub.add_parser("followups", help="list leads with a follow-up due, oldest first").set_defaults(fn=cmd_followups) + p = sub.add_parser("show", help="show a lead with its score breakdown") p.add_argument("id", type=int) p.set_defaults(fn=cmd_show) diff --git a/tests/test_app.py b/tests/test_app.py index 870acd2..7b7cfad 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -4,6 +4,7 @@ import os import tempfile import unittest +from unittest.mock import patch from datetime import datetime, timezone from helpers import NOW, FakeFetcher, cfg @@ -94,6 +95,41 @@ def run_cli(self, *args): code = cli.main(["--db", self.db, "--config", self.ini, *args]) return code, out.getvalue() + def test_followups_empty(self): + code, out = self.run_cli("followups") + self.assertEqual(code, 0) + self.assertIn("no follow-ups due", out) + self.assertNotIn("leadhound scan", out) + + def test_followups_respects_config_and_does_not_change_outreach(self): + config.save(cfg(follow_up_days=7, follow_up_max=1), self.ini) + s = Store(self.db) + with patch("leadhound.store.time.time", return_value=NOW): + for eid, days, action in (("oldest", 10, ""), ("due", 8, ""), + ("recent", 4, ""), ("replied", 9, "replied"), + ("stopped", 9, "nofollow"), ("maxed", 9, "followup")): + lid, _ = s.upsert(lead(eid, budget="$100")) + s.update(lid, status="contacted") + if action == "replied": + s.update(lid, status=action) + elif action: + s.log(lid, action) + s.db.execute("UPDATE activity SET at = ? WHERE lead_id = ?", (NOW - days * 86400, lid)) + s.db.commit() + before = [tuple(row) for row in s.db.execute("SELECT * FROM activity ORDER BY id")] + code, out = self.run_cli("followups") + self.assertEqual(code, 0) + self.assertIn("Lead oldest", out) + self.assertIn("Lead due", out) + self.assertIn("[$100]", out) + self.assertLess(out.index("Lead oldest"), out.index("Lead due")) + for eid in ("a", "recent", "replied", "stopped", "maxed"): + self.assertNotIn(f"Lead {eid}", out) + self.assertEqual(before, [tuple(row) for row in s.db.execute("SELECT * FROM activity ORDER BY id")]) + config.save(cfg(follow_up_max=0), self.ini) + self.assertIn("no follow-ups due", self.run_cli("followups")[1]) + s.close() + def test_flow(self): self.assertEqual(self.run_cli("init")[0], 0) self.assertEqual(config.load(self.ini).llm_provider, "none")