diff --git a/codimd_export.py b/codimd_export.py index cfb60d1a5f6daef1c0f8953bebd7489dc3be906a..6824df7dee46dc551caf9a7956fcce597b9b6a7b 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 0000000000000000000000000000000000000000..75bf5414fa2aff1e43f168942b788958ef735e64 --- /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")