Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodiMD export script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stgroup
misc
CodiMD export script
Commits
18127beb
Commit
18127beb
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Refactor HedgeDoc importer, Export urls to visit to file
parent
13f564f9
No related branches found
No related tags found
1 merge request
!1
Hedgedoc import
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
hedgedoc_import.py
+30
-5
30 additions, 5 deletions
hedgedoc_import.py
md-import-export.py
+2
-2
2 additions, 2 deletions
md-import-export.py
with
34 additions
and
8 deletions
.gitignore
+
2
−
1
View file @
18127beb
...
...
@@ -9,3 +9,4 @@ codimd-documents/
.idea
*.zip
hedgedoc_documents_to_visit.url
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hedgedoc_import.py
+
30
−
5
View file @
18127beb
...
...
@@ -35,6 +35,7 @@ def import_single_document(instance_url, hedgedoc_free_url, content, session_id)
def
import_into_hedgedoc
(
instance_url
,
session_id
,
export_folder
,
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
:
...
...
@@ -48,6 +49,12 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
# URLs to visit to make the new document available in the history
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
)
def
iterate_over_archive
(
archive_file
,
instance_url
,
lookup_map
,
session_id
,
urls_to_visit
):
# iterate over files in archive
with
ZipFile
(
archive_file
)
as
zf
:
print
(
"
Now scanning your provided archive file containing the documents you are the owner of
"
)
...
...
@@ -63,27 +70,45 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
if
document_title
in
lookup_map
:
print
(
f
"
\t
You visited your own document
\"
{
document_title
}
\"
.md) via the path
"
+
f
"
\t
You visited your own document
\"
{
document_title
}
\"
.md) via the
identifier/
path
"
+
f
"
\"
{
lookup_map
[
document_title
]
}
\"
"
)
print
(
f
"
\t
Trying to migrate this document and make it available under the already visited path
"
)
try
:
new_url
=
import_single_document
(
instance_url
,
lookup_map
[
document_title
],
document_content
,
session_id
)
urls_to_visit
.
append
(
new_url
)
print
(
f
"
\t
Migration was possible. New URL:
{
instance_url
}
/
{
lookup_map
[
document_title
]
}
"
)
except
HTTPError
as
error
:
if
error
.
status
==
409
:
print
(
"
\t
HTTP 409. Uploading anyways (new path, random ID)
"
)
print
(
"
\t
ATTENTION: Could not migrate document with the same path. Uploading anyways and
"
"
creating a new, random path
"
)
new_url
=
import_single_document
(
instance_url
,
""
,
document_content
,
session_id
)
print
(
f
"
New URL after document migration without migrating the URL/subpath:
{
new_url
}
"
)
urls_to_visit
.
append
(
new_url
)
else
:
print
(
"
no mapping found for
"
,
document_title
,
"
, uploading anyway
"
)
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
"
)
# empty string implies HedgeDoc should create a new ID
urls_to_visit
.
append
(
import_single_document
(
instance_url
,
""
,
document_content
,
session_id
))
generated_url
=
import_single_document
(
instance_url
,
""
,
document_content
,
session_id
)
print
(
f
"
New URL after document migration with new, random URL/subpath:
"
f
"
{
generated_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
):
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
"
...
...
@@ -109,4 +134,4 @@ def select_browser():
if
__name__
==
"
__main__
"
:
import_into_hedgedoc
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
"
codimd-documents
"
)
"
codimd-documents
"
,
"
archive.zip
"
)
This diff is collapsed.
Click to expand it.
md-import-export.py
+
2
−
2
View file @
18127beb
...
...
@@ -4,5 +4,5 @@ from hedgedoc_import import import_into_hedgedoc
if
__name__
==
"
__main__
"
:
export_folder
=
"
codimd-documents
"
export_from_codimd
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
connect.sid
"
),
export_folder
)
import_into_hedgedoc
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
export_folder
,
"
archive.zip
"
)
\ No newline at end of file
export_from_codimd
(
"
http://localhost:3001
"
,
get_sessionid
(
"
connect.sid
"
),
export_folder
)
import_into_hedgedoc
(
"
http://hedgedoc:3000
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
export_folder
,
"
archive.zip
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment