Skip to content
Snippets Groups Projects
Commit 49b317d4 authored by Martin Morgenstern's avatar Martin Morgenstern
Browse files

Improve the robustness of the prompt (especially on Windows)

parent a034abc5
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ Now, the instructions are similar for Chrome and Firefox:
3. **Chrome**: go to the "Application" tab. **Firefox**: go to the "Storage" tab ("Web-Speicher").
4. Un-collapse "Cookies".
5. In the list, search for a cookie with the name `connect.sid`
6. Select and copy the value.
6. Select and copy the value. It must start with the character sequence `s%3A`.
### 2. Execute the script via the command line
......
......@@ -4,13 +4,17 @@ Save all Markdown documents in your CodiMD history to a local directory.
"""
import json
import os
import sys
from getpass import getpass
from pathlib import Path
from urllib.error import HTTPError
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
def slurp(url, session_id):
"""Retrieve a (protected) CodiMD resource and return it as a bytes object."""
......@@ -56,10 +60,10 @@ def main(instance_url, session_id, export_to):
def get_sessionid():
"""Ask the user for the session id, if it's not configured as an envvar."""
try:
return os.environ["CMD_SESSIONID"]
except KeyError:
return getpass("Please provide your CodiMD session id (connect.sid cookie): ")
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__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment