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

Exit script if importing fails

parent 1f30c1cc
No related branches found
No related tags found
1 merge request!1Hedgedoc import
......@@ -17,7 +17,11 @@ def import_single_document(instance_url, hedgedoc_free_url, content, session_id)
req = urllib.request.Request(request_url, data=str.encode(content), method='POST', headers=headers)
# unfortunately, no error is thrown if a document is not created when session cookie is invalid
# HTTP 409 is ignored for the sake of simplicity. Handled in import_into_hedgedoc(..)
# Not optimal, but nobody ain't got time for that
with urllib.request.urlopen(req) as response:
if response.url == instance_url + "/":
raise SystemExit("Could not import document. Please check your HedgeDoc session cookie. Aborting...")
return response.url
......@@ -75,8 +79,9 @@ def process_archive_export(archive_file, instance_url, lookup_map, session_id, u
try_generate_free_url_document(document_content, document_title, instance_url, lookup_map, session_id,
urls_to_visit)
else:
print(f"According to your history, you did not visit \"{document_title}.md\" in the CodiMD "
"instance recently. Migrating the document and generating a new, random URL/path for it")
print(
f"According to your history (or lack thereof) , you did not visit \"{document_title}.md\" in the "
f"CodiMD instance recently. Migrating the document and generating a new, random URL/path for it")
# empty string implies HedgeDoc should create a new ID
generated_url = import_single_document(instance_url, "", document_content, session_id)
print(f"New URL after document migration with new, random URL/subpath: "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment