Skip to content

Commit

Permalink
Better command-line behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Nov 29, 2023
1 parent 5de8948 commit a16097b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fec.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ def search(
seen_contacts = set()

for contact in contact_provider.get_contacts():
if contact in seen_contacts:
if contact.without_zip() in seen_contacts:
continue
seen_contacts.add(contact)
seen_contacts.add(contact.without_zip())
manager = state_to_manager.get(contact.state)
if manager is None:
manager = ContributionSummaryManager(
Expand Down
4 changes: 4 additions & 0 deletions server/data/contacts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def to_data(self) -> dict[str, str]:
data["zip_code"] = self.zip_code
return data

def without_zip(self) -> "Contact":
"""Return a copy of the contact without the zip code."""
return Contact(self.first_name, self.last_name, self.city, self.state, None)


class IContactProvider(t.Protocol):
"""Defines a simple protocol for getting critical contact information."""
Expand Down
4 changes: 4 additions & 0 deletions server/data/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def preferred_summary_for_contact(
) -> ContributionSummary | None:
"""Return the largest contribution summary for a contact."""
summaries = list(self._summaries_for_contact(contact))
if contact.zip5:
contact_no_zip = contact.without_zip()
more_summaries = list(self._summaries_for_contact(contact_no_zip))
summaries.extend(more_summaries)
if not summaries:
return None
return max(summaries, key=lambda s: s.total_cents)

0 comments on commit a16097b

Please sign in to comment.