diff --git a/import_md/hedgedoc_import.py b/import_md/hedgedoc_import.py index 72a68386d2e8caa3f08b7f926fa0cf5665abe2bf..990e49c11d0e46188720f85d09d6aac3a48b1edb 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 = []