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

Move import and export scripts to explicit locations

parent 49102d4b
No related branches found
No related tags found
1 merge request!1Hedgedoc import
......@@ -59,4 +59,4 @@ def export_from_codimd(instance_url, session_id, export_to):
if __name__ == "__main__":
export_from_codimd("https://md.inf.tu-dresden.de", get_sessionid("connect.sid"), "codimd-documents")
export_from_codimd("https://md.inf.tu-dresden.de", get_sessionid("CodiMD", "connect.sid"), "codimd-documents")
......@@ -41,11 +41,9 @@ def check_archive_exists(archive_file):
def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
print("Beginning import")
print("Beginning import_md")
check_archive_exists(archive_file)
check_accessibility(instance_url, session_id)
# let user select browser
browser = select_browser()
# get exported history map
with open(os.path.join(export_folder, "history.json")) as map_file:
history_dictionary = json.load(map_file)
......@@ -59,8 +57,7 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
urls_to_visit = []
iterate_over_archive(archive_file, instance_url, lookup_map, session_id, urls_to_visit)
visit_urls_in_browser(browser, urls_to_visit)
create_urls_to_visit_file("hedgedoc_documents_to_visit.url", urls_to_visit)
create_urls_to_visit_file("../hedgedoc_documents_to_visit.url", urls_to_visit)
def iterate_over_archive(archive_file, instance_url, lookup_map, session_id, urls_to_visit):
......@@ -104,43 +101,16 @@ def iterate_over_archive(archive_file, instance_url, lookup_map, session_id, url
urls_to_visit.append(generated_url)
def visit_urls_in_browser(browser, urls_to_visit):
print("Your specified browser now needs to visit every newly created document to ensure that it's available in"
"your history in HedgeDoc")
subprocess.run([browser] + urls_to_visit)
def create_urls_to_visit_file(filename, urls_to_visit):
print(f"A new file {filename} will be created. It contains all URLs you need to visit in order to make the"
f"migrated documents appear in your HedgeDoc history.")
print("This can be automated by running the scripts in the directory \"history_scripts\"")
print("BE AWARE: Opening a lot of tabs might be quite resource-intensive.")
with open(filename, 'w') as f:
for url in urls_to_visit:
f.write(url + "\n")
print(
"In preparation for the case that this did not work, all URLs are saved in the file \"hedgedoc_documents_to_visit.url\"")
def select_browser():
print("Once you've uploaded all your documents, they unfortunately do not appear in your HedgeDoc history.")
print("To make sure that they are available to you, this script automatically visits all your newly uploaded "
"documents in your browser.")
print("Therefore, you need to specify your browser. It needs to be on your path with the same name as "
"specified here")
print("ATTENTION - this needs to be a browser where you have an active and logged-in HedgeDoc session")
supported_browsers = ["firefox", "opera", "safari", "google-chrome", "chromium"]
user_input = ''
input_message = "Specify a browser which holds an active and logged-in HedgeDoc session:\n"
for i, browser_suggestion in enumerate(supported_browsers):
input_message += f'{i + 1}) {browser_suggestion}\n'
# input_message += 'Your choice: '
while user_input not in map(str, range(1, len(supported_browsers) + 1)):
user_input = input(input_message)
print('You chose: ' + supported_browsers[int(user_input) - 1])
return supported_browsers[int(user_input) - 1]
if __name__ == "__main__":
import_into_hedgedoc("https://md.inf.tu-dresden.de/notes", get_sessionid("connect.hedgeDoc.sid"),
"codimd-documents", "archive.zip")
import_into_hedgedoc("https://md.inf.tu-dresden.de/notes", get_sessionid("HedgeDoc", "connect.hedgeDoc.sid"),
"codimd-documents", "../archive.zip")
from codimd_export import export_from_codimd
from export_md.codimd_export import export_from_codimd
from import_md.hedgedoc_import import import_into_hedgedoc
from common import get_sessionid
from hedgedoc_import import import_into_hedgedoc
if __name__ == "__main__":
export_folder = "codimd-documents"
export_archive = "archive.zip"
export_from_codimd("https://md.inf.tu-dresden.de/", get_sessionid("CodiMD", "connect.sid"), export_folder)
import_into_hedgedoc("https://md.inf.tu-dresden.de/notes", get_sessionid("HedgeDoc", "connect.hedgeDoc.sid"),
export_from_codimd("http://localhost:3001", get_sessionid("CodiMD", "connect.sid"), export_folder)
import_into_hedgedoc("http://hedgedoc:3000", get_sessionid("HedgeDoc", "connect.hedgeDoc.sid"),
export_folder, export_archive)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment