Skip to content
Snippets Groups Projects
Commit 8dbbed1e authored by Andreas Domanowski's avatar Andreas Domanowski
Browse files

Extract cookie prompt

parent 3a941074
Branches
No related tags found
1 merge request!1Hedgedoc import
...@@ -4,17 +4,12 @@ Save all Markdown documents in your CodiMD history to a local directory. ...@@ -4,17 +4,12 @@ Save all Markdown documents in your CodiMD history to a local directory.
""" """
import json import json
import sys
from pathlib import Path from pathlib import Path
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.parse import quote from urllib.parse import quote
from urllib.request import Request, urlopen from urllib.request import Request, urlopen
if not sys.platform.startswith("win"): from common import get_sessionid
from getpass import getpass
else:
# on Windows, Ctrl-V doesn't work with getpass()
getpass = input
def slurp(url, session_id): def slurp(url, session_id):
...@@ -59,13 +54,5 @@ def main(instance_url, session_id, export_to): ...@@ -59,13 +54,5 @@ def main(instance_url, session_id, export_to):
print(f"Done: {num_ok} notes successfully downloaded, {num_fail} not accessible.") 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__": if __name__ == "__main__":
main("https://md.inf.tu-dresden.de", get_sessionid(), "codimd-documents") main("https://md.inf.tu-dresden.de", get_sessionid(), "codimd-documents")
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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment