from CreateTableAndOffsets import convert_to_table from ExpandDB import expand_dbs from manejoArchivos import select_file, open_file_explorer from FileSystem import * from S7_DBParser import parse_dbs, parse_udts from Excel import * if __name__ == "__main__": file_path = select_file() if file_path: # Proceed only if a file was selected with open(file_path, "r", encoding="utf-8-sig") as file: lines = file.readlines() file_name, extension, dest_path = extract_file_details(file_path) dest_path = create_directory(dest_path, file_name) json_path = build_file_path(dest_path, file_name, "json") xml_path = build_file_path(dest_path, file_name, "xml") excel_path = build_file_path(dest_path, file_name, "xlsx") cvs_path = build_file_path(dest_path, file_name, "cvs") udt_json = parse_udts(lines) db_json = parse_dbs(lines, udt_json) expand_dbs(udt_json, db_json) # Expand DBs with UDT definitions save_data_as_json(db_json, json_path) # Display the expanded DBs as a table df = convert_to_table(db_json) save_dataframe_to_file(df, cvs_path) # Save the DataFrame to a CSV file ## EXCEL output save_dataframe_to_excel( df, excel_path, file_name ) # Optionally, save the DataFrame to an Excel file workbook, worksheet = open_worksheet(excel_path, file_name) autosize_columns(worksheet, ["A", "B", "C", "D", "E", "F", "G"]) center_columns(worksheet, ["C", "D", "E"]) save_workbook(workbook, excel_path) # Save JSON data to an XML file save_json_to_xml(db_json, xml_path) # Open the directory containing the new file in Explorer open_file_explorer(os.path.dirname(excel_path)) else: print("No file was selected.")