from lib.helpers import ( get_attachments_folder_path, get_document_space, write_csv, ) import os from pathlib import Path def create_odts_import(CONFIG): rows = [] for current_path, folders, files in os.walk(CONFIG["absolute_starting_path"]): if files: odts = list( filter( lambda f: os.path.splitext(f)[-1].lower() == ".odt", files, ), ) if odts: document_space = get_document_space(CONFIG, current_path) attachements_folder_path = get_attachments_folder_path( CONFIG, current_path ) lines = list( map( lambda odtf: { "documentSpace": document_space + "." + odtf.replace(".odt", "").replace(".", "_"), "documentName": "WebHome", "documentTitle": Path(odtf).stem.replace(".odt", ""), "attachmentsFolderPath": attachements_folder_path + "/" + odtf, "pilot": CONFIG["pilot"], }, odts, ) ) rows.extend(lines) write_csv( f"{CONFIG['export_directory']}/export-odts-pages.csv", CONFIG["fields"], rows )