Skip to content

Commit

Permalink
chore(actionnetwork): Type checks should use isinstance (#889)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal Levy <[email protected]>
Co-authored-by: sharinetmc <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent 58e6054 commit 0b9db94
Showing 1 changed file with 15 additions and 11 deletions.
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

0 comments on commit 0b9db94

Please sign in to comment.