From fb68d8cd3e6852ec3e7a673a101e50c218b67298 Mon Sep 17 00:00:00 2001 From: Andreas Domanowski <andreas@domanowski.net> Date: Thu, 2 Mar 2023 12:13:54 +0100 Subject: [PATCH] Proceed import with non-existent history file --- import_md/hedgedoc_import.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/import_md/hedgedoc_import.py b/import_md/hedgedoc_import.py index 72a6838..990e49c 100644 --- a/import_md/hedgedoc_import.py +++ b/import_md/hedgedoc_import.py @@ -33,13 +33,21 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file): f"Checking existence of archive file ({archive_file})") check_file_exists(archive_file) # get exported history map - with open(os.path.join(export_folder, "history.json")) as map_file: - history_dictionary = json.load(map_file) + history_json_filename = "history.json" + history_dictionary = {} + try: + with open(os.path.join(export_folder, "%s" % history_json_filename)) as map_file: + history_dictionary = json.load(map_file) + except FileNotFoundError: + print_block_heading( + f"INFO: could not find file {history_json_filename}. Continuing anyways with random generated paths for " + f"documents") # mapping from title of a document (= filename without md extension in archive) to its id (= note url in CodiMD) lookup_map = {} - for entry in history_dictionary["history"]: - lookup_map[entry["text"]] = entry["id"] + if "history" in history_dictionary: + for entry in history_dictionary["history"]: + lookup_map[entry["text"]] = entry["id"] # URLs to visit to make the new document available in the history urls_to_visit = [] -- GitLab