From 8dbbed1e44ca9ae101e8f414062685bdf8bdbb1d Mon Sep 17 00:00:00 2001
From: Andreas Domanowski <andreas@domanowski.net>
Date: Tue, 28 Feb 2023 11:28:22 +0100
Subject: [PATCH] Extract cookie prompt

---
 codimd_export.py | 15 +--------------
 common.py        | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 14 deletions(-)
 create mode 100644 common.py

diff --git a/codimd_export.py b/codimd_export.py
index cfb60d1..6824df7 100755
--- a/codimd_export.py
+++ b/codimd_export.py
@@ -4,17 +4,12 @@ Save all Markdown documents in your CodiMD history to a local directory.
 """
 
 import json
-import sys
 from pathlib import Path
 from urllib.error import HTTPError
 from urllib.parse import quote
 from urllib.request import Request, urlopen
 
-if not sys.platform.startswith("win"):
-    from getpass import getpass
-else:
-    # on Windows, Ctrl-V doesn't work with getpass()
-    getpass = input
+from common import get_sessionid
 
 
 def slurp(url, session_id):
@@ -59,13 +54,5 @@ def main(instance_url, session_id, export_to):
     print(f"Done: {num_ok} notes successfully downloaded, {num_fail} not accessible.")
 
 
-def get_sessionid():
-    """Ask the user for the session id, if it's not configured as an envvar."""
-    sid = getpass("Please provide your CodiMD session id (connect.sid cookie): ")
-    if sid.startswith("s%3A"):
-        return sid
-    raise SystemExit(f"error: the supplied session id seems to be malformed")
-
-
 if __name__ == "__main__":
     main("https://md.inf.tu-dresden.de", get_sessionid(), "codimd-documents")
diff --git a/common.py b/common.py
new file mode 100644
index 0000000..75bf541
--- /dev/null
+++ b/common.py
@@ -0,0 +1,15 @@
+import sys
+
+if not sys.platform.startswith("win"):
+    from getpass import getpass
+else:
+    # on Windows, Ctrl-V doesn't work with getpass()
+    getpass = input
+
+
+def get_sessionid():
+    """Ask the user for the session id, if it's not configured as an envvar."""
+    sid = getpass("Please provide your CodiMD session id (connect.sid cookie): ")
+    if sid.startswith("s%3A"):
+        return sid
+    raise SystemExit(f"error: the supplied session id seems to be malformed")
-- 
GitLab