Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion leadhound/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,28 @@ def cmd_list(a, cfg):
if not leads:
print("no leads. Run: leadhound scan or leadhound local \"<city>\"")
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):
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down