"""Parses a XLSX file to a dict.""" from os.path import exists, split, join, splitext import pandas as pd from constants.file import INPUT_FILE_EXT_LIST import config def parse_perfomer_metadata(performer_data_file: object) -> list: """Ingest an Excel file to a dict, sifted and pivoted on various fields. Args: performer_data_file (object): Performer metadata filestream. Returns: list: The contents of the file, sifted and pivoted. """ # Log opening and loading file to user msg = f'Opening and loading \'{performer_data_file}\'.' # Open Excel file as dataframe with pd.ExcelFile(performer_data_file) as xl: # Loop through all sheets for sheet_name in xl.sheet_names: sheet = pd.read_excel(xl, sheet_name=sheet_name) sheet_data = sheet.to_dict('records') return sheet_data