Work on IDAA data import
This commit is contained in:
@@ -31,13 +31,13 @@ router = APIRouter()
|
||||
async def importing_update_w_external_id(
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
account_id = 13
|
||||
full_file_path = 'admin/temp/import_person_external_id.xlsx'
|
||||
full_file_path = 'admin/temp/import_person_external_id.csv'
|
||||
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_id':str, 'email':str, 'External ID':str, 'Email Address':str})
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id':str, 'External ID':str, 'source_id':str, 'Source ID':str, 'email':str, 'Email Address':str})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
@@ -52,20 +52,30 @@ async def importing_update_w_external_id(
|
||||
log.info('No external ID was found.')
|
||||
continue
|
||||
|
||||
if source_id := record.get('source_id', None): pass
|
||||
elif source_id := record.get('Source ID', None): pass
|
||||
else:
|
||||
log.debug('No source ID was found.')
|
||||
pass
|
||||
|
||||
|
||||
if email := record.get('email', None): pass
|
||||
elif email := record.get('Email Address', None): pass
|
||||
else:
|
||||
log.info('No email address was found.')
|
||||
continue
|
||||
log.debug(f'External ID: {external_id}, Source ID {source_id}, Email: {email}')
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['email'] = email
|
||||
|
||||
sql = f"""
|
||||
SELECT *
|
||||
FROM `v_person` AS `person`
|
||||
WHERE person.account_id = :account_id
|
||||
AND person.email = :email
|
||||
AND (external_id IS NULL OR external_import_id IS NULL)
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
@@ -85,16 +95,20 @@ async def importing_update_w_external_id(
|
||||
person_data = {}
|
||||
person_data['id'] = person_id
|
||||
person_data['external_id'] = external_id
|
||||
person_data['external_import_id'] = email
|
||||
if source_id:
|
||||
person_data['external_import_id'] = source_id
|
||||
else:
|
||||
person_data['external_import_id'] = email
|
||||
log.debug(person_data)
|
||||
|
||||
if person_obj_up_result := sql_update(data=person_data, table_name='person'):
|
||||
log.debug(person_obj_up_result)
|
||||
else:
|
||||
log.warning(person_obj_up_result)
|
||||
continue # Something unexpected may have happened
|
||||
person_rec = person_rec_result
|
||||
else:
|
||||
continue # Something unexpected may have happened
|
||||
log.info(f'No record found that needs to be updated. Email: {email}')
|
||||
continue
|
||||
|
||||
person_data_min = {}
|
||||
person_data_min['person_id'] = person_id
|
||||
@@ -103,7 +117,7 @@ async def importing_update_w_external_id(
|
||||
person_data_li.append(person_data_min)
|
||||
log.debug(f"Record processed: {person_id} {person_rec.get('full_name', None)}")
|
||||
|
||||
return mk_resp(data=person_data_li)
|
||||
return mk_resp(data=person_data_li, response=response)
|
||||
|
||||
|
||||
# Based on the Cvent Address Book Contacts export data. New External IDs should already be added in Cvent and updated in Aether as well. Use importing_update_w_external_id() endpoint function.
|
||||
|
||||
Reference in New Issue
Block a user