Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(actionnetwork): Edge case and cleaning up type checking #889

Merged
Merged
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
26 changes: 15 additions & 11 deletions parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,39 +171,39 @@ def upsert_person(
Adds a person to Action Network
"""
email_addresses_field = None
if type(email_address) == str:
if isinstance(email_address, str):
email_addresses_field = [{"address": email_address}]
elif type(email_address) == list:
if type(email_address[0]) == str:
elif isinstance(email_address, list):
if isinstance(email_address[0], str):
email_addresses_field = [{"address": email} for email in email_address]
email_addresses_field[0]["primary"] = True
if type(email_address[0]) == dict:
if isinstance(email_address[0], dict):
email_addresses_field = email_address

mobile_numbers_field = None
if type(mobile_number) == str:
if isinstance(mobile_number, str):
mobile_numbers_field = [
{"number": re.sub("[^0-9]", "", mobile_number), "status": mobile_status}
]
elif type(mobile_number) == int:
elif isinstance(mobile_number, int):
mobile_numbers_field = [
{"number": str(mobile_number), "status": mobile_status}
]
elif type(mobile_number) == list:
elif isinstance(mobile_number, list):
if len(mobile_number) > 1:
raise ("Action Network allows only 1 phone number per activist")
if type(mobile_number[0]) == str:
if isinstance(mobile_number[0], list):
mobile_numbers_field = [
{"number": re.sub("[^0-9]", "", cell), "status": mobile_status}
for cell in mobile_number
]
mobile_numbers_field[0]["primary"] = True
if type(mobile_number[0]) == int:
if isinstance(mobile_number[0], int):
mobile_numbers_field = [
{"number": cell, "status": mobile_status} for cell in mobile_number
]
mobile_numbers_field[0]["primary"] = True
if type(mobile_number[0]) == dict:
if isinstance(mobile_number[0], dict):
mobile_numbers_field = mobile_number

if not email_addresses_field and not mobile_numbers_field:
Expand Down Expand Up @@ -242,7 +242,11 @@ def upsert_person(
entry_id.split(":")[1]
for entry_id in identifiers
if "action_network:" in entry_id
][0]
]
if not person_id:
logger.error(f"Response gave no valid person_id: {identifiers}")
else:
person_id = person_id[0]
if response["created_date"] == response["modified_date"]:
logger.info(f"Entry {person_id} successfully added.")
else:
Expand Down