diff --git a/app/main.py b/app/main.py index 1eb12b2..0687a65 100644 --- a/app/main.py +++ b/app/main.py @@ -387,6 +387,7 @@ origins = [ 'http://cmsc.oneskyit.local:5000', 'http://idaa.oneskyit.local:5000', 'http://ishlt.oneskyit.local:5000', + 'http://businessgroup.oneskyit.local:5000', 'http://dev-ishlt.localhost:5000', # Using localhost 'http://ishlt.localhost:5000', # Using localhost diff --git a/app/methods/account_methods.py b/app/methods/account_methods.py index bc1626b..899ab52 100644 --- a/app/methods/account_methods.py +++ b/app/methods/account_methods.py @@ -591,7 +591,7 @@ def get_account_rec_list( sql = f""" SELECT `account`.id AS 'account_id', `account`.id_random AS 'account_id_random' FROM `account` AS `account` - WHERE + WHERE 1=1 {sql_enabled} ORDER BY `account`.created_on DESC, `account`.updated_on DESC {sql_limit}; diff --git a/app/methods/event_methods.py b/app/methods/event_methods.py index 838cf0b..47d37d2 100644 --- a/app/methods/event_methods.py +++ b/app/methods/event_methods.py @@ -67,7 +67,7 @@ def load_event_obj( exclude_unset: bool = True, model_as_dict: bool = False, ) -> Event_Base|bool: - log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass diff --git a/app/routers/importing.py b/app/routers/importing.py index b51652b..41f7f38 100644 --- a/app/routers/importing.py +++ b/app/routers/importing.py @@ -4,7 +4,7 @@ from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Resp from pydantic import BaseModel, EmailStr, Field from typing import Dict, List, Optional, Set, Union -from app.lib_general import log, logging, secure_hash_string +from app.lib_general import log, logging, secure_hash_string, common_route_params, Common_Route_Params from app.config import settings from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random @@ -1622,3 +1622,107 @@ async def importing_cont_edu_cert_person_data_touch( # break log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL return mk_resp(data=cont_edu_cert_person_data_li) + + + +# Business Group on Health program import +# Updated 2022-04-06 +@router.get('/bgh_program_import', response_model=Resp_Body_Base) +async def bgh_program_import( + begin_at: int = 0, + end_at: int = 100, + # response: Response = Response, + + commons: Common_Route_Params = Depends(common_route_params), + ): + log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(locals()) + + account_id = commons.x_account_id # 4 GpLf_bnywCs + event_id = 1446 + + full_file_path = 'admin/temp/import_bgh_2022-04_program_data.csv' + + df = pandas.read_csv( + full_file_path, + na_filter = False, + dtype = { + 'session_code': str, + 'Session Code': str, + 'session_title': str, + 'session_description': str, + 'session_start_datetime': str, + 'session_end_datetime': str, + 'session_location': str, + 'session_location_code': str, + }, + parse_dates = ['session_start_datetime', 'session_end_datetime'] + ) + #df = df.fillna('') # replace NaN with '' + # df = df.fillna(None) + # df = df.fillna('', inplace=True) + #return str(df.info()) + + df.rename(columns={ + 'Presenter Code': 'presenter_code', + 'Presentation Code': 'presentation_code', + 'Session Code': 'session_code', + 'session_title': 'session_name', + 'Session Title': 'session_name', + 'session_location_code': 'location_code', + 'session_location': 'location_name', + }, + inplace = True) + + log.debug(df) + + # datetime.datetime.strptime(updated_on, '%d-%b-%Y') + + df_dict = df.to_dict(orient='records') + log.debug(df_dict) + + from app.methods.event_session_methods import create_event_session_obj, create_update_event_session_obj_v4, load_event_session_obj, get_event_session_rec_list, update_event_session_obj_v3, update_event_session_obj + + from app.models.event_session_models import Event_Session_Base + + session_dict_li = [] + for record in df_dict: + session_dict = {} + session_dict['code'] = record.get('session_code') + session_dict['name'] = record.get('session_name') + session_dict['description'] = record.get('session_description') + session_dict['start_datetime'] = record.get('session_start_datetime') + session_dict['end_datetime'] = record.get('session_end_datetime') + location_name = record.get('location_name') + if location_name == 'Broadway 1': session_dict['event_location_id'] = 301 + elif location_name == 'Broadway 2': session_dict['event_location_id'] = 302 + elif location_name == 'Broadway 3': session_dict['event_location_id'] = 303 + elif location_name == 'Grand Ballroom': session_dict['event_location_id'] = 304 + elif location_name == 'Sobro': session_dict['event_location_id'] = 305 + + create_update_event_session_obj_v4_result = create_update_event_session_obj_v4( + event_session_dict_obj = session_dict, + event_id = event_id + ) + + log.debug(create_update_event_session_obj_v4_result) + + session_dict_li.append(session_dict) + + # try: + # event_session_obj = Event_Session_Base(**session_dict) + # log.debug(event_session_obj) + # except ValidationError as e: + # log.error(e.json()) + # break + # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + + # 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 + # else: + # log.warning(f'Event Session not created.') + # log.debug(event_session_dict_in_result) + # return False + # log.debug(event_session_dict_in_result) + + + return mk_resp(data=session_dict_li, response=commons.response) \ No newline at end of file