Work on Confex API and Impexium API

This commit is contained in:
Scott Idem
2023-04-12 15:30:46 -04:00
parent f24382fb10
commit c4fad68192
4 changed files with 122 additions and 23 deletions

View File

@@ -159,7 +159,7 @@ def get_event_presentation_detail(
confex_session_id: str,
confex_presentation_id: str, # similar to 'Paper/99999'
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# if result := authenticate():

View File

@@ -504,7 +504,7 @@ def create_update_event_session_obj_v4(
return False
log.debug(event_session_dict_up_result)
else:
if event_session_dict_in_result := sql_insert(data=event_session_dict, table_name='event_session', rm_id_random=True, id_random_length=8): pass
if event_session_dict_in_result := sql_insert(data=event_session_dict, table_name='event_session', rm_id_random=True, id_random_length=None): pass
else:
log.warning(f'Event Session not created.')
log.debug(event_session_dict_in_result)

View File

@@ -12,6 +12,7 @@ from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_
from app.methods.e_impexium_methods import get_custom_fields, get_events, get_event_registrants, get_individual_custom_fields, get_individual_profile
from app.methods.event_session_methods import create_update_event_session_obj_v4
# from app.methods.event_person_methods import create_event_person_obj, create_update_event_person_obj_v4, get_event_person_rec_list, load_event_person_obj, update_event_person_obj, update_event_person_obj_v3
from app.methods.e_confex_methods import get_event_session_list, get_event_session_detail, get_event_presentation_detail, get_event_presenter_detail
@@ -28,7 +29,7 @@ router = APIRouter()
async def import_event_session_list(
e_confex_event_id: str = Query(..., min_length=5, max_length=22), # For AAPOR: aapor_2023 (2023-05)
event_id: str = Query(..., min_length=11, max_length=22), # For AAPOR: x2H2P2MYlXU (2023-05)
event_id: str = Query(..., min_length=11, max_length=22), # For AAPOR: 9jW-Db-SF-wt (1478 2023-05); x2H2P2MYlXU (1447 2022-05)
# Account ID For AAPOR: j5EBhRDqPuw
return_detail: bool = False,
@@ -60,24 +61,41 @@ async def import_event_session_list(
# BEGIN: Loop through the sessions pulled from Confex
loop_count = 0
loop_limit = 5 # 200
event_session_data = {}
event_session_data_li = []
loop_limit = 200 # 200
event_session_summary_li = []
for event_session in event_session_li:
if loop_count > loop_limit: break
log.warning(f'BEGIN: **** *** ** * Confex event session import loop #{loop_count} * ** *** ****')
confex_session_id = event_session.get('id')
event_session_data = {}
event_session_data['event_session_external_id'] = event_session.get('id')
event_session_data['event_session_name'] = event_session.get('Title')
event_session_data['event_session_start_end_datetime'] = event_session.get('SortableTimeString')
event_session_summary = {}
event_session_summary['event_session_external_id'] = event_session.get('id')
event_session_summary['event_session_name'] = event_session.get('Title')
session_time_parts = event_session.get('SortableTimeString').split('_')
session_start_datetime_str = session_time_parts[0]+'T'+session_time_parts[1]
session_end_datetime_str = session_time_parts[0]+'T'+session_time_parts[2]
event_session_summary['event_session_start_datetime'] = session_start_datetime_str
event_session_summary['event_session_end_datetime'] = session_end_datetime_str
event_session_summary['event_session_start_end_datetime'] = event_session.get('SortableTimeString')
# end_time???
event_session_data['event_session_type'] = event_session.get('ProgramCode')
event_session_data['event_session_type_name'] = event_session.get('ProgramTitle')
event_session_data['event_session_subject_name'] = event_session.get('SubjectTitle')
event_session_data['event_session_file_list'] = event_session.get('Child_MediaFiles')
event_session_summary['event_session_type'] = event_session.get('ProgramCode')
event_session_summary['event_session_type_name'] = event_session.get('ProgramTitle')
event_session_summary['event_session_subject_name'] = event_session.get('SubjectTitle')
event_session_summary['event_session_file_list'] = event_session.get('Child_MediaFiles')
event_session_data = {}
event_session_data['external_id'] = event_session.get('id')
event_session_data['name'] = event_session.get('Title')
event_session_data['start_datetime'] = session_start_datetime_str
event_session_data['end_datetime'] = session_end_datetime_str
# event_session_data['event_session_start_end_datetime'] = event_session.get('SortableTimeString')
# end_time???
# event_session_data['event_session_type'] = event_session.get('ProgramCode')
# event_session_data['event_session_type_name'] = event_session.get('ProgramTitle')
# event_session_data['event_session_subject_name'] = event_session.get('SubjectTitle')
# event_session_data['event_session_file_list'] = event_session.get('Child_MediaFiles')
# SortableTimeString - '2023-05-11_08:00:00_09:30:00'
@@ -92,12 +110,74 @@ async def import_event_session_list(
confex_session_detail = get_event_session_detail(confex_session_id = confex_session_id)
event_session_data['event_presentation_list'] = None
event_session_qry = {}
event_session_qry['event_id'] = event_id
event_session_qry['external_id'] = confex_session_id
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_session_qry)
sql_select_event_session = f"""
SELECT id AS event_session_id, id_random AS event_session_id_random, external_id AS event_session_external_id, event_location_id AS event_location_id
FROM `event_session` AS `event_session`
WHERE event_session.event_id = :event_id
AND event_session.external_id = :external_id
/*LIMIT 1*/;
"""
log.debug(sql_select_event_session)
try:
event_session_obj = Event_Session_Base(**event_session_data)
log.warning(event_session_obj)
except ValidationError as e:
log.error(e.json())
return False
if event_session_result := sql_select(sql=sql_select_event_session, data=event_session_qry):
if isinstance(event_session_result, list):
log.error(f'Found more than one Event Session with the same External ID. Count: {len(event_session_result)}')
break
# return False
else:
event_session_id = event_session_result.get('event_session_id')
log.info(f'Found Event Session. Updating existing... Event Session ID: {event_session_id}')
if create_event_session_obj_result := create_update_event_session_obj_v4(
event_session_dict_obj = event_session_obj,
event_session_id = event_session_id,
event_id = event_id,
):
event_session_id = create_event_session_obj_result
log.warning(f'Event Session updated. Event Session ID: {event_session_id}')
else:
log.warning(f'Event Session not updated. Event Session ID: {event_session_id}')
log.debug(create_event_session_obj_result)
break
# return False
else:
log.info('No Event Session found. Creating new...')
if create_event_session_obj_result := create_update_event_session_obj_v4(
event_session_dict_obj = event_session_obj,
event_id = event_id,
):
event_session_id = create_event_session_obj_result
log.warning(f'Event Session created. Event Session ID: {event_session_id}')
else:
log.warning(f'Event Session not created.')
log.debug(create_event_session_obj_result)
break
# return False
event_session_data['event_session_id'] = event_session_id # _random
event_session_data['event_presentation_list'] = None # Confex "Paper"
if confex_session_detail:
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(f'Session Detail: {confex_session_detail}')
# Presentation List
event_session_summary['event_presentation_list'] = []
event_session_data['event_presentation_list'] = []
for confex_presentation_paper in confex_session_detail.get('ChildList_Paper'):
@@ -106,13 +186,30 @@ async def import_event_session_list(
event_presentation_data = {}
event_presentation_data['external_id'] = confex_presentation_id
log.info('Confex: Getting presentation detail...')
confex_presentation_detail = get_event_presentation_detail(confex_session_id = confex_session_id, confex_presentation_id = confex_presentation_id)
if confex_presentation_detail:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(f'Presentation Detail: {confex_presentation_detail}')
event_presentation_data['event_presentation_name'] = confex_presentation_detail.get('Title')
event_presentation_data['event_presentation_start_end_datetime'] = confex_presentation_detail.get('SortableTimeString')
# Presentation File List (not Presenter specific???)
event_presentation_data['event_file_list'] = []
for confex_vendor_file in confex_presentation_detail.get('ChildList_VendorFiles'):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(confex_vendor_file)
event_file = {}
event_file['filename'] = confex_vendor_file.get('Filename')
event_file['ext'] = confex_vendor_file.get('Ext')
event_file['size'] = confex_vendor_file.get('Size') # in bytes?
event_file['file_purpose'] = confex_vendor_file.get('Table') # 'Handout', 'Presentation'
event_file['url'] = confex_vendor_file.get('URL')
event_presentation_data['event_file_list'].append(event_file)
# Presenter Information
event_presentation_data['event_presenter_full_name'] = confex_presentation_detail.get('SubmitterFullName')
@@ -125,7 +222,7 @@ async def import_event_session_list(
event_presenter_data['external_id'] = confex_presenter_id
confex_presenter_detail = get_event_presenter_detail(confex_session_id = confex_session_id, confex_presentation_id = confex_presentation_id, confex_presenter_id = confex_presenter_id)
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if confex_presenter_detail:
log.debug(f'Presenter Detail: {confex_presenter_detail}')
@@ -137,7 +234,7 @@ async def import_event_session_list(
event_session_data['event_presentation_list'].append(event_presentation_data)
event_session_summary['event_presentation_list'].append(event_presentation_data)
# event_session.get('Child_MediaFiles')
else:
@@ -146,8 +243,8 @@ async def import_event_session_list(
# event_session_data['details'] = confex_session_detail
event_session_data_li.append(event_session_data)
event_session_summary_li.append(event_session_summary)
loop_count = loop_count + 1
return mk_resp(data=event_session_data_li, status_code=501, response=commons.response) # Not Implemented
return mk_resp(data=event_session_summary_li, status_code=200, response=commons.response) # Partially implemented...

View File

@@ -242,10 +242,12 @@ async def event_import_reg(
country_alpha_2_code = None
country = None
if details:
if emails := event_registrant.get('emails'):
if isinstance(emails, list) and len(emails):
email = emails[0].get('address')
event_person_summary_data['email'] = email
if email := event_registrant.get('email'):
event_person_summary_data['email'] = email
# if emails := event_registrant.get('emails'):
# if isinstance(emails, list) and len(emails):
# email = emails[0].get('address')
# event_person_summary_data['email'] = email
if addresses := event_registrant.get('addresses'):
if isinstance(addresses, list) and len(addresses):