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|
|
|
|
|
|
|
|
if 'access_token' in api:
|
|
|
|
|
access_token = api.get('access_token')
|
|
|
|
|
log.info(f'Cvent Access Token found: {access_token}')
|
|
|
|
|
log.debug(f'Cvent Access Token found: {access_token}')
|
|
|
|
|
else:
|
|
|
|
|
log.info(f'Cvent Access Token was not found. Will request one.')
|
|
|
|
|
if 'expire_on' in api and datetime.datetime.now() < api['expire_on']:
|
|
|
|
|
expire_on = api.get('expire_on')
|
|
|
|
|
log.info(f'Cvent Access Token is current: {expire_on}')
|
|
|
|
|
log.debug(f'Cvent Access Token is current: {expire_on}')
|
|
|
|
|
return api
|
|
|
|
|
else:
|
|
|
|
|
expire_on = api.get('expire_on')
|
|
|
|
|
log.info(f'Cvent Access Token is not current. Requesting a new one. Expired On: {expire_on}')
|
|
|
|
|
|
|
|
|
|
endpoint = '/oauth2/token'
|
|
|
|
|
uri = api['base_url']+endpoint
|
|
|
|
|
@@ -60,19 +65,8 @@ def get_access_token():
|
|
|
|
|
api['expires_in'] = response_data['expires_in']
|
|
|
|
|
api['token_type'] = response_data['token_type']
|
|
|
|
|
|
|
|
|
|
# current_datetime = datetime.datetime.now()
|
|
|
|
|
# log.debug(type(current_datetime))
|
|
|
|
|
# log.debug(current_datetime)
|
|
|
|
|
|
|
|
|
|
# expires_in = response_data['expires_in']
|
|
|
|
|
# log.debug(type(expires_in))
|
|
|
|
|
# log.debug(expires_in)
|
|
|
|
|
|
|
|
|
|
api['expire_on'] = datetime.datetime.now() + datetime.timedelta(seconds=response_data['expires_in'])
|
|
|
|
|
|
|
|
|
|
# log.debug(type(api['expire_on']))
|
|
|
|
|
# log.debug(api['expire_on'])
|
|
|
|
|
|
|
|
|
|
api['headers']['Accept'] = 'application/json'
|
|
|
|
|
api['headers']['x-api-key'] = app['client_id']
|
|
|
|
|
api['headers']['Authorization'] = 'Bearer '+api['access_token']
|
|
|
|
|
@@ -80,7 +74,7 @@ def get_access_token():
|
|
|
|
|
log.debug(api)
|
|
|
|
|
|
|
|
|
|
log.warning('Sleeping for 1 second to avoid Cvent rate limit...')
|
|
|
|
|
time.sleep(1.5)
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
return api
|
|
|
|
|
|
|
|
|
|
@@ -141,14 +135,20 @@ def get_contact_list(external_id: str=None, email: str=None):
|
|
|
|
|
response_data = resp.json()
|
|
|
|
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests for Cvent API': return False
|
|
|
|
|
|
|
|
|
|
return response_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Cvent Methods ### get_recent_contact_list() ###
|
|
|
|
|
# Updated 2022-02-02
|
|
|
|
|
@logger_reset
|
|
|
|
|
def get_recent_contact_list(created_on=None, updated_on=None):
|
|
|
|
|
def get_recent_contact_list(
|
|
|
|
|
from_created_on = datetime.datetime.utcnow() + datetime.timedelta(minutes=-60),
|
|
|
|
|
to_created_on = datetime.datetime.utcnow(),
|
|
|
|
|
from_updated_on = datetime.datetime.utcnow() + datetime.timedelta(minutes=-60),
|
|
|
|
|
to_updated_on = None,
|
|
|
|
|
):
|
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.debug(locals())
|
|
|
|
|
|
|
|
|
|
@@ -158,20 +158,26 @@ def get_recent_contact_list(created_on=None, updated_on=None):
|
|
|
|
|
uri = api['base_url']+endpoint
|
|
|
|
|
|
|
|
|
|
params = {}
|
|
|
|
|
if created_on and updated_on:
|
|
|
|
|
created_on_str = created_on.isoformat()
|
|
|
|
|
updated_on_str = updated_on.isoformat()
|
|
|
|
|
log.info(f'Created On: {created_on_str}')
|
|
|
|
|
log.info(f'Updated On: {updated_on_str}')
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and created gt '{created_on_str}Z' or lastModified gt '{updated_on_str}Z'"
|
|
|
|
|
elif created_on:
|
|
|
|
|
created_on_str = created_on.isoformat()
|
|
|
|
|
log.info(f'Created On: {created_on_str}')
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and created gt '{created_on_str}Z'"
|
|
|
|
|
|
|
|
|
|
from_created_on_str = from_created_on.isoformat()
|
|
|
|
|
log.info(f'From Created On: {from_created_on_str}')
|
|
|
|
|
if to_created_on:
|
|
|
|
|
to_created_on_str = to_created_on.isoformat()
|
|
|
|
|
log.info(f'To Created On: {to_created_on_str}')
|
|
|
|
|
|
|
|
|
|
from_updated_on_str = from_updated_on.isoformat()
|
|
|
|
|
log.info(f'From Updated On: {from_updated_on_str}')
|
|
|
|
|
if to_updated_on:
|
|
|
|
|
to_updated_on_str = to_updated_on.isoformat()
|
|
|
|
|
log.info(f'To Updated On: {to_updated_on_str}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if from_created_on and from_updated_on and to_created_on and to_updated_on:
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and (created gt '{from_created_on_str}Z' or lastModified gt '{from_updated_on_str}Z') and (created lt '{to_created_on_str}Z' or lastModified lt '{to_updated_on_str}Z')"
|
|
|
|
|
elif from_created_on and to_created_on:
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and created gt '{from_created_on_str}Z' and created lt '{to_created_on_str}Z'"
|
|
|
|
|
elif updated_on:
|
|
|
|
|
updated_on_str = updated_on.isoformat()
|
|
|
|
|
log.info(f'Updated On: {updated_on_str}')
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and lastModified gt '{updated_on_str}Z'"
|
|
|
|
|
params['filter'] = f"deleted eq 'False' and lastModified gt '{from_updated_on_str}Z'"
|
|
|
|
|
else:
|
|
|
|
|
log.warning('Created On or Updated On is requried. Returing False')
|
|
|
|
|
return False
|
|
|
|
|
@@ -181,24 +187,21 @@ def get_recent_contact_list(created_on=None, updated_on=None):
|
|
|
|
|
response_data = resp.json()
|
|
|
|
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests for Cvent API': return False
|
|
|
|
|
|
|
|
|
|
return response_data
|
|
|
|
|
# ### END ### API Cvent Methods ### get_recent_contact_list() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Cvent Methods ### get_contact_id() ###
|
|
|
|
|
# Updated 2022-02-01
|
|
|
|
|
@logger_reset
|
|
|
|
|
def get_contact_id(contact_id: str):
|
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.debug(locals())
|
|
|
|
|
|
|
|
|
|
# if 'access_token' in api: pass
|
|
|
|
|
# else: get_access_token()
|
|
|
|
|
get_access_token()
|
|
|
|
|
|
|
|
|
|
# log.warning('Sleeping for 1 second to avoid Cvent rate limit...')
|
|
|
|
|
# time.sleep(1)
|
|
|
|
|
|
|
|
|
|
endpoint = f'/contacts/{contact_id}'
|
|
|
|
|
uri = api['base_url']+endpoint
|
|
|
|
|
|
|
|
|
|
@@ -209,22 +212,26 @@ def get_contact_id(contact_id: str):
|
|
|
|
|
response_data = resp.json()
|
|
|
|
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests for Cvent API': return False
|
|
|
|
|
|
|
|
|
|
return response_data
|
|
|
|
|
# ### END ### API Cvent Methods ### get_contact_id() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Cvent Methods ### modify_contact_id() ###
|
|
|
|
|
# Updated 2022-02-01
|
|
|
|
|
@logger_reset
|
|
|
|
|
def modify_contact_id(contact_id: str, field_list: list=[], custom_field_id: str=None, custom_field_value: str=None):
|
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.debug(locals())
|
|
|
|
|
|
|
|
|
|
get_access_token()
|
|
|
|
|
|
|
|
|
|
if custom_field_id:
|
|
|
|
|
log.info(f'Updating Cvent Custom Field ID: {custom_field_id}')
|
|
|
|
|
endpoint = f'/contacts/{contact_id}/custom-fields/{custom_field_id}/answers'
|
|
|
|
|
elif field_list:
|
|
|
|
|
log.info(f'Updating Cvent Field List: {field_list}')
|
|
|
|
|
endpoint = f'/contacts/{contact_id}'
|
|
|
|
|
else:
|
|
|
|
|
log.error('Missing required parameters')
|
|
|
|
|
@@ -246,12 +253,14 @@ def modify_contact_id(contact_id: str, field_list: list=[], custom_field_id: str
|
|
|
|
|
else:
|
|
|
|
|
resp = requests.patch(url=uri, headers=api['headers'], params=params, json=data)
|
|
|
|
|
|
|
|
|
|
log.info('Updated Cvent Contact ID: {contact_id}')
|
|
|
|
|
response_data = resp.json()
|
|
|
|
|
log.debug(json.dumps(response_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests': return False
|
|
|
|
|
if 'message' in response_data and response_data['message'] == 'Too Many Requests for Cvent API': return False
|
|
|
|
|
|
|
|
|
|
return response_data
|
|
|
|
|
# ### END ### API Cvent Methods ### modify_contact_id() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API External Cvent ### create_update_aether_person() ###
|
|
|
|
|
@@ -308,7 +317,9 @@ def create_update_aether_person(
|
|
|
|
|
address_data['city'] = cvent_contact_obj.get('homeAddress').get('city')
|
|
|
|
|
address_data['state_province'] = cvent_contact_obj.get('homeAddress').get('region')
|
|
|
|
|
if cvent_contact_obj.get('homeAddress').get('countryCode') and cvent_contact_obj.get('homeAddress').get('regionCode'):
|
|
|
|
|
country_subdivision_code = cvent_contact_obj.get('homeAddress').get('countryCode') +'-'+ cvent_contact_obj.get('homeAddress').get('regionCode')
|
|
|
|
|
# NOTE: There needs to be a better fix for this. Why does Cvent include the 3 character country code only sometimes???
|
|
|
|
|
cvent_region_code = cvent_contact_obj.get('homeAddress').get('regionCode').replace('(AUS)', '')
|
|
|
|
|
country_subdivision_code = cvent_contact_obj.get('homeAddress').get('countryCode') +'-'+ cvent_region_code
|
|
|
|
|
address_data['country_subdivision_code'] = country_subdivision_code
|
|
|
|
|
address_data['postal_code'] = cvent_contact_obj.get('homeAddress').get('postalCode')
|
|
|
|
|
address_data['country_alpha_2_code'] = cvent_contact_obj.get('homeAddress').get('countryCode')
|
|
|
|
|
@@ -322,8 +333,8 @@ def create_update_aether_person(
|
|
|
|
|
# user_data['name'] =
|
|
|
|
|
user_data['username'] = cvent_contact_obj.get('email')
|
|
|
|
|
user_data['email'] = cvent_contact_obj.get('email')
|
|
|
|
|
random_password_string = secrets.token_urlsafe(8)
|
|
|
|
|
user_data['password'] = secure_hash_string(string=random_password_string)
|
|
|
|
|
# random_password_string = secrets.token_urlsafe(8)
|
|
|
|
|
# user_data['password'] = secure_hash_string(string=random_password_string)
|
|
|
|
|
|
|
|
|
|
user_data['email_verified'] = True # Assuming this is True because they came from another system where the email address is required.
|
|
|
|
|
|
|
|
|
|
@@ -337,11 +348,7 @@ def create_update_aether_person(
|
|
|
|
|
|
|
|
|
|
user_data['public'] = False
|
|
|
|
|
user_data['verified'] = True
|
|
|
|
|
user_data['notes'] = 'Created by importing list'
|
|
|
|
|
|
|
|
|
|
other_data = {}
|
|
|
|
|
other_data['temp_password'] = random_password_string
|
|
|
|
|
user_data['other_json'] = json.dumps(other_data, indent=4)
|
|
|
|
|
person_data['user'] = user_data
|
|
|
|
|
|
|
|
|
|
if cvent_contact_obj.get('type'):
|
|
|
|
|
@@ -379,8 +386,6 @@ def create_update_aether_person(
|
|
|
|
|
|
|
|
|
|
membership_person_data = {}
|
|
|
|
|
membership_person_type_data = {}
|
|
|
|
|
# NOTE: Should this be renamed to contact_type_id and contact_type_name???
|
|
|
|
|
# Technically the membership type naming is slightly different and more of them.
|
|
|
|
|
# if cvent_contact_type_name:
|
|
|
|
|
if cvent_contact_obj.get('membership'):
|
|
|
|
|
if cvent_contact_type_name == 'Al-Anon Member' or cvent_contact_type_name == 'Al-Anon Members':
|
|
|
|
|
@@ -426,12 +431,7 @@ def create_update_aether_person(
|
|
|
|
|
membership_person_type_data['enable'] = True
|
|
|
|
|
|
|
|
|
|
membership_person_data['membership_person_type'] = membership_person_type_data
|
|
|
|
|
log.debug(json.dumps(membership_person_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
# ### TESTING BREAK POINT ###
|
|
|
|
|
# person_data['membership_person'] = membership_person_data
|
|
|
|
|
# return False
|
|
|
|
|
# ### TESTING BREAK POINT ###
|
|
|
|
|
# log.debug(json.dumps(membership_person_data, indent=2, default=str))
|
|
|
|
|
|
|
|
|
|
# Try to look up using external ID
|
|
|
|
|
if not person_id and person_external_id:
|
|
|
|
|
@@ -474,8 +474,8 @@ def create_update_aether_person(
|
|
|
|
|
custom_field_id = '609ab766-7d79-4a9d-a72c-f126412659ee' # IDAA Cvent External ID UUID
|
|
|
|
|
custom_field_value = [person_external_id]
|
|
|
|
|
|
|
|
|
|
log.warning('Sleeping for 1 second to avoid Cvent rate limit...')
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
log.warning('Sleeping for .75 second to avoid Cvent rate limit...')
|
|
|
|
|
time.sleep(.75)
|
|
|
|
|
|
|
|
|
|
contact_mod_result = modify_contact_id(
|
|
|
|
|
contact_id = cvent_contact_id, # This is the Cvent Contact UUID for a person
|
|
|
|
|
@@ -500,10 +500,12 @@ def create_update_aether_person(
|
|
|
|
|
membership_person_id = person_obj.membership_person.id
|
|
|
|
|
if person_obj.membership_person.membership_person_type:
|
|
|
|
|
membership_person_type_id = person_obj.membership_person.membership_person_type.id
|
|
|
|
|
else: membership_person_type_id = None
|
|
|
|
|
|
|
|
|
|
if not person_obj.external_id:
|
|
|
|
|
person_data['external_id'] = person_external_id
|
|
|
|
|
log.debug(person_data)
|
|
|
|
|
|
|
|
|
|
if update_person_kiss(person_id=person_id, person_dict_obj=person_data):
|
|
|
|
|
log.info(f'Updated Person ID: {person_id}')
|
|
|
|
|
else:
|
|
|
|
|
@@ -511,12 +513,16 @@ def create_update_aether_person(
|
|
|
|
|
else:
|
|
|
|
|
# ### SECTION ### Create new person and related with the person_data and membership_person_data dicts.
|
|
|
|
|
|
|
|
|
|
# person_data['id'] = person_id
|
|
|
|
|
person_data['account_id'] = account_id
|
|
|
|
|
# person_data['contact']['id'] = person_obj.contact.id
|
|
|
|
|
# person_data['contact']['address']['id'] = person_obj.contact.address.id
|
|
|
|
|
# person_data['user']['id'] = person_obj.user.id
|
|
|
|
|
person_data['notes'] = 'Created using data from Cvent'
|
|
|
|
|
random_password_string = secrets.token_urlsafe(8)
|
|
|
|
|
person_data['user']['password'] = secure_hash_string(string=random_password_string)
|
|
|
|
|
user_data['notes'] = 'Created using data from Cvent'
|
|
|
|
|
# other_data = {}
|
|
|
|
|
# other_data['temp_password'] = random_password_string
|
|
|
|
|
# person_data['user']['other_json'] = json.dumps(other_data, indent=4)
|
|
|
|
|
log.debug(person_data)
|
|
|
|
|
|
|
|
|
|
if create_person_obj_result := create_person_kiss(account_id=account_id, person_dict_obj=person_data):
|
|
|
|
|
person_id = create_person_obj_result
|
|
|
|
|
log.info(f'Created Person ID: {person_id}')
|
|
|
|
|
@@ -528,20 +534,23 @@ def create_update_aether_person(
|
|
|
|
|
# return False
|
|
|
|
|
# ### TESTING BREAK POINT ###
|
|
|
|
|
|
|
|
|
|
if cvent_contact_type_id and membership_person_id:
|
|
|
|
|
# membership_person_id = person_obj.membership_person.id
|
|
|
|
|
membership_person_data['id'] = membership_person_id
|
|
|
|
|
membership_person_data['membership_person_type']['id'] = membership_person_type_id
|
|
|
|
|
if update_membership_person_obj(membership_person_id=membership_person_id, membership_person_dict_obj=membership_person_data):
|
|
|
|
|
log.info(f'Updated Membership Person ID: {membership_person_id}')
|
|
|
|
|
if cvent_contact_obj.get('membership'):
|
|
|
|
|
if cvent_contact_type_id and membership_person_id:
|
|
|
|
|
# membership_person_id = person_obj.membership_person.id
|
|
|
|
|
membership_person_data['id'] = membership_person_id
|
|
|
|
|
membership_person_data['membership_person_type']['id'] = membership_person_type_id
|
|
|
|
|
if update_membership_person_obj(membership_person_id=membership_person_id, membership_person_dict_obj=membership_person_data):
|
|
|
|
|
log.info(f'Updated Membership Person ID: {membership_person_id}')
|
|
|
|
|
else:
|
|
|
|
|
log.info(f'Did not update Membership Person ID: {membership_person_id}')
|
|
|
|
|
elif cvent_contact_type_id:
|
|
|
|
|
if create_membership_person_obj_result := create_membership_person_obj(account_id=account_id, person_id=person_id, membership_person_dict_obj=membership_person_data):
|
|
|
|
|
membership_person_id = create_membership_person_obj_result
|
|
|
|
|
log.info(f'Created Membership Person ID: {membership_person_id}')
|
|
|
|
|
else:
|
|
|
|
|
log.info(f'Did not create Membership Person')
|
|
|
|
|
else:
|
|
|
|
|
log.info(f'Did not update Membership Person ID: {membership_person_id}')
|
|
|
|
|
elif cvent_contact_type_id:
|
|
|
|
|
if create_membership_person_obj_result := create_membership_person_obj(account_id=account_id, person_id=person_id, membership_person_dict_obj=membership_person_data):
|
|
|
|
|
membership_person_id = create_membership_person_obj_result
|
|
|
|
|
log.info(f'Created Membership Person ID: {membership_person_id}')
|
|
|
|
|
else:
|
|
|
|
|
log.info(f'Did not create Membership Person')
|
|
|
|
|
membership_person_data = {}
|
|
|
|
|
else:
|
|
|
|
|
membership_person_data = {}
|
|
|
|
|
|
|
|
|
|
|