From 853f1a71d27c346445a3383d49554569e76ab511 Mon Sep 17 00:00:00 2001
From: Andreas Domanowski <andreas@domanowski.net>
Date: Thu, 2 Mar 2023 11:48:37 +0100
Subject: [PATCH] Write history.json only once

---
 export_md/codimd_export.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/export_md/codimd_export.py b/export_md/codimd_export.py
index 45e2bff..18a931e 100755
--- a/export_md/codimd_export.py
+++ b/export_md/codimd_export.py
@@ -43,6 +43,8 @@ def export_from_codimd(instance_url, session_id, export_to):
     target_dir = prepare_target_dir(export_to)
     num_ok = num_fail = 0
     print_block_heading(f"Accessing history and trying to fetch each document")
+    with open(Path(target_dir, f"history.json"), mode="w") as stream:
+        json.dump(data, stream)
     print("Hold on, this may take a while...")
     for row in data["history"]:
         document_id = row["id"]
@@ -51,8 +53,6 @@ def export_from_codimd(instance_url, session_id, export_to):
             contents = slurp(f"{document_url}/download", session_id)
             with open(Path(target_dir, f"{document_id}.md"), mode="wb") as stream:
                 stream.write(contents)
-            with open(Path(target_dir, f"history.json"), mode="w") as stream:
-                json.dump(data, stream)
             num_ok += 1
         except HTTPError as error:
             # history might reference deleted or otherwise inaccessible notes
-- 
GitLab