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
b622ec75
Commit
b622ec75
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Add cli frontend
parent
0167600e
No related branches found
No related tags found
1 merge request
!1
Hedgedoc import
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
codimd_export.py
+5
-2
5 additions, 2 deletions
codimd_export.py
hedgedoc_import.py
+34
-8
34 additions, 8 deletions
hedgedoc_import.py
md-import-export.py
+7
-0
7 additions, 0 deletions
md-import-export.py
with
46 additions
and
10 deletions
codimd_export.py
+
5
−
2
View file @
b622ec75
...
...
@@ -8,6 +8,7 @@ from pathlib import Path
from
urllib.error
import
HTTPError
from
urllib.parse
import
quote
from
urllib.request
import
Request
,
urlopen
import
sys
from
common
import
get_sessionid
...
...
@@ -28,7 +29,7 @@ def prepare_target_dir(pathname):
return
target_dir
def
main
(
instance_url
,
session_id
,
export_to
):
def
export_from_codimd
(
instance_url
,
session_id
,
export_to
):
"""
Retrieve CodiMD document history and try to download each document.
"""
try
:
data
=
json
.
loads
(
slurp
(
f
"
{
instance_url
}
/history
"
,
session_id
))
...
...
@@ -45,6 +46,8 @@ def main(instance_url, session_id, export_to):
contents
=
slurp
(
f
"
{
document_url
}
/download
"
,
session_id
)
with
open
(
Path
(
target_dir
,
f
"
{
document_id
}
.md
"
),
mode
=
"
wb
"
)
as
stream
:
stream
.
write
(
contents
)
with
open
(
Path
(
target_dir
,
f
"
map.map
"
),
mode
=
"
w
"
)
as
stream
:
json
.
dump
(
data
,
stream
)
num_ok
+=
1
except
HTTPError
as
error
:
# history might reference deleted or otherwise inaccessible notes
...
...
@@ -55,4 +58,4 @@ def main(instance_url, session_id, export_to):
if
__name__
==
"
__main__
"
:
main
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
connect.sid
"
),
"
codimd-documents
"
)
export_from_codimd
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
connect.sid
"
),
"
codimd-documents
"
)
This diff is collapsed.
Click to expand it.
hedgedoc_import.py
+
34
−
8
View file @
b622ec75
#!/usr/bin/env python3
from
common
import
get_sessionid
from
pathlib
import
Path
import
urllib.parse
import
urllib.request
import
os
from
pathlib
import
Path
from
common
import
get_sessionid
import
subprocess
from
zipfile
import
ZipFile
def
import_document
(
instance_url
,
hedgedoc_free_url
,
content
,
session_id
):
def
import_
single_
document
(
instance_url
,
hedgedoc_free_url
,
content
,
session_id
):
sanitized_free_url
=
hedgedoc_free_url
.
replace
(
"
"
,
"
%20
"
)
user_agent
=
'
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)
'
...
...
@@ -22,18 +23,43 @@ def import_document(instance_url, hedgedoc_free_url, content, session_id):
print
(
"
Go visit
"
+
response
.
url
+
"
with your browser in a logged-in session.
"
)
def
main
(
instance_url
,
session_id
,
im
port_f
rom
):
folder
=
os
.
path
.
join
(
os
.
getcwd
(),
im
port_f
rom
);
def
import_into_hedgedoc
(
instance_url
,
session_id
,
ex
port_f
older
,
archive_file
):
folder
=
os
.
path
.
join
(
os
.
getcwd
(),
ex
port_f
older
);
print
(
"
Trying to upload all files with extension
\"
.md
\"
in folder
\"
"
+
folder
+
"
\"
"
);
#with ZipFile('images.zip') as zf:
# for file in zf.namelist():
# if not file.endswith('.png'): # optional filtering by filetype
# continue
# with zf.open(file) as f:
# image = pygame.image.load(f, namehint=file)
for
relative_filename
in
os
.
listdir
(
folder
):
if
relative_filename
.
endswith
(
"
.md
"
):
addressable_filename
=
os
.
path
.
join
(
folder
,
relative_filename
)
print
(
"
Trying to upload:
"
+
addressable_filename
)
markdown_content
=
Path
(
addressable_filename
).
read_text
()
free_url
=
Path
(
relative_filename
).
stem
import_document
(
instance_url
,
free_url
,
markdown_content
,
session_id
)
import_single_document
(
instance_url
,
free_url
,
markdown_content
,
session_id
)
def
select_browser
():
options
=
[
'
chrome
'
,
'
firefox
'
,
'
opera
'
]
user_input
=
''
input_message
=
"
Pick an option:
\n
"
for
index
,
item
in
enumerate
(
options
):
input_message
+=
f
'
{
index
+
1
}
)
{
item
}
\n
'
input_message
+=
'
Your choice:
'
while
user_input
not
in
map
(
str
,
range
(
1
,
len
(
options
)
+
1
)):
user_input
=
input
(
input_message
)
print
(
'
You picked:
'
+
options
[
int
(
user_input
)
-
1
])
if
__name__
==
"
__main__
"
:
main
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
"
codimd-documents
"
)
select_browser
()
#subprocess.run(["firefox", "www.google.de"])
#import_into_hedgedoc("https://md.inf.tu-dresden.de/notes", get_sessionid("connect.hedgeDoc.sid"), "codimd-documents")
This diff is collapsed.
Click to expand it.
md-import-export.py
0 → 100644
+
7
−
0
View file @
b622ec75
from
codimd_export
import
export_from_codimd
from
common
import
get_sessionid
from
hedgedoc_import
import
import_into_hedgedoc
if
__name__
==
"
__main__
"
:
export_from_codimd
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
connect.sid
"
),
"
codimd-documents
"
)
import_into_hedgedoc
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
"
codimd-documents
"
,
"
archive.zip
"
)
\ No newline at end of file
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