Skip to content

Commit

Permalink
fixup! Add contact_io interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Dec 22, 2024
1 parent 519be42 commit 6d0e61f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/twfy_tools/utils/contact_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from datetime import date, timedelta
from functools import lru_cache

from typer import Typer

Expand All @@ -14,9 +15,15 @@
)
from twfy_tools.db.models import OptinValues, User

app = Typer()

mailing_list_name = "mySociety Newsletters"

app = Typer()

@lru_cache
def get_mailing_list_internal_id():
client = MailChimpHandler(config.MAILCHIMP_API_KEY)
return client.list_name_to_unique_id(mailing_list_name)


def get_internal_optin_id(
Expand All @@ -25,7 +32,7 @@ def get_internal_optin_id(
client = MailChimpHandler(config.MAILCHIMP_API_KEY)

# get internal id for the mailing list
mailing_list_id = client.list_name_to_unique_id(mailing_list_name)
mailing_list_id = get_mailing_list_internal_id()
interest_group_items = client.get_interest_group(mailing_list_id, interest_group)
return interest_group_items.interest_name_to_id[interest_name]

Expand Down Expand Up @@ -62,7 +69,7 @@ def upload_contacts(start_date: date, end_date: date):
members_and_values.append(MemberAndInterests(user.email, internal_ids))

client = MailChimpHandler(config.MAILCHIMP_API_KEY)
mailing_list_id = client.list_name_to_unique_id(mailing_list_name)
mailing_list_id = get_mailing_list_internal_id()

client.batch_add_to_different_interest_groups(mailing_list_id, members_and_values)

Expand Down

0 comments on commit 6d0e61f

Please sign in to comment.