Skip to content

Commit

Permalink
Process apple contact book backups.
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Nov 27, 2023
1 parent 6052131 commit c0422f8
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 380 deletions.
70 changes: 58 additions & 12 deletions fec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import click

from server.data.contacts import Contact, IContactProvider, SimpleContactProvider
from server.data.contacts.abbu import DirectoryABBUManager, ZipABBUManager
from server.data.fec.committees import CommitteeManager
from server.data.fec.contributions import (
ContributionsManager,
Expand Down Expand Up @@ -92,29 +94,73 @@ def summarize(data: str | None = None):


@contributions.command()
@click.argument("first_name")
@click.argument("last_name")
@click.argument("zip_code")
@click.argument("first_name", required=False, default=None)
@click.argument("last_name", required=False, default=None)
@click.argument("zip_code", required=False, default=None)
@click.option(
"-c",
"--contact-dir",
type=click.Path(exists=True, dir_okay=True, file_okay=False),
help="Path to a `.abbu` contacts dir.",
required=False,
default=None,
)
@click.option(
"-z",
"--contact-zip",
type=click.Path(exists=True, dir_okay=False, file_okay=True),
help="Path to a `.abbu` contacts zip file.",
required=False,
default=None,
)
@click.option(
"--data",
type=click.Path(exists=True),
help="Path to data dir.",
required=False,
default=None,
)
def search(first_name: str, last_name: str, zip_code: str, data: str | None = None):
def search(
first_name: str | None = None,
last_name: str | None = None,
zip_code: str | None = None,
data: str | None = None,
contact_dir: str | None = None,
contact_zip: str | None = None,
):
"""Search summarized FEC contributions data."""
data_manager = DataManager(data) if data is not None else DataManager.default()
nicknames_manager = NicknamesManager.from_data_manager(data_manager)
fuzzy_id = FuzzyIdentifier(
last_name, first_name, zip_code, get_nickname_index=nicknames_manager
).fuzzy_id
summaries_manager = ContributionSummariesManager.from_data_manager(data_manager)
summary = summaries_manager.get_summary(fuzzy_id)
if summary is None:
print("No matching summary.")
else:
print(json.dumps(summary.to_data(), indent=2))

contact_provider: IContactProvider | None = None

if contact_dir is not None:
contact_provider = DirectoryABBUManager(contact_dir)
elif contact_zip is not None:
contact_provider = ZipABBUManager(contact_zip)
elif first_name and last_name and zip_code:
singleton = Contact(first_name, last_name, zip_code)
contact_provider = SimpleContactProvider([singleton])

if contact_provider is None:
raise click.UsageError(
"You must provide a contact dir, zip file, or explicit name & zip."
)

for contact in contact_provider.get_contacts():
fuzzy_id = FuzzyIdentifier(
contact.last,
contact.first,
contact.zip_code,
get_nickname_index=nicknames_manager,
).fuzzy_id
summary = summaries_manager.get_summary(fuzzy_id)
print(f"--> {contact.first} {contact.last} {contact.zip_code}")
if summary is None:
print("{}")
else:
print(json.dumps(summary.to_data(), indent=2))


if __name__ == "__main__":
Expand Down
293 changes: 0 additions & 293 deletions munge.py

This file was deleted.

Loading

0 comments on commit c0422f8

Please sign in to comment.