diff --git a/cove_bods/process.py b/cove_bods/process.py index 2ab2f7c..02253e6 100644 --- a/cove_bods/process.py +++ b/cove_bods/process.py @@ -13,6 +13,7 @@ import json import os.path +import pandas import flattentool from sentry_sdk import capture_exception @@ -30,6 +31,21 @@ logger = getLogger(__name__) +def check_table_file_new(filename): + if filename.endswith(".xlxs"): + data = pandas.read_excel(filename) + if "statementID" in data.head(): + return False + else: + return True + else: + with open(filename) as file: + head = file.readline() + if "statementID" in data.head(): + return False + else: + return True + def create_error_file(directory: str, name: str, data: dict): """Create temporary error file""" filename = os.path.join(directory, f"{name}-error.json") @@ -185,11 +201,16 @@ def process(self, process_data: dict) -> dict: # We don't know what schema version the spreadsheet is in. Use default schema. schema = SchemaBODS() + if check_table_file_new(input_filename): + statement_id_name = "statementID" + else: + statement_id_name = "statementId" + unflatten_kwargs = { "output_name": os.path.join(output_dir, "unflattened.json"), "root_list_path": "there-is-no-root-list-path", - "root_id": "statementID", - "id_name": "statementID", + "root_id": statement_id_name, + "id_name": statement_id_name, "root_is_list": True, "input_format": get_file_type_for_flatten_tool(supplied_data_json_file), "schema": schema.pkg_schema_url,