Skip to content
Snippets Groups Projects

Hedgedoc import

Merged Andreas Domanowski requested to merge hedgedoc-import into main
1 file
+ 53
30
Compare changes
  • Side-by-side
  • Inline
+ 58
31
# CodiMD note exporter
````
 
WARNING - Use this script at your own discretion. It's a prototype and not exhaustively tested and might throw HTTP errors that were not encounted for.
 
````
This little tool is intended to help you backup the notes that you have in your CodiMD history to a
# CodiMD Note Exporter + Hedgedoc Note Importer
local folder. It complements CodiMD's "export user data" functionality, which only downloads
documents that you own.
This little tool is intended to help you **backup** the notes that your CodiMD history shows to a local folder.
 
It complements CodiMD's "export user data" functionality, which only downloads
 
documents that you are the owner of.
 
This backup is not meant to be uploaded by you in its entirety, since this would create ownership issues of shared
 
documents.
 
 
The export user data functionality of CodiMD creates an archive containing all the documents you are the owner of.
 
This tool furthermore implements functionality to upload each or a selection of your owned documents based on this
 
archive.
 
Based upon the path the document was served under at CodiMD, this script tries to migrate the document to the exact same
 
path if possible, e.g., https://md.inf.tu-dresden.de/my_custom_path gets mapped
 
to https://md.inf.tu-dresden.de/notes/my_custom_path
 
 
Be aware that this approach is a little hacky.
 
Unfortunately, this is necessary since our CodiMD instance did use KeyCloak as an OAuth provider.
 
 
Follow the steps closely to ensure that everything works as intended and that the ownership of documents is not messed
 
up.
## Requirements
## Requirements
@@ -10,9 +29,21 @@ Its only dependency is Python >= 3.7 (use `python3 -V` to check your version).
@@ -10,9 +29,21 @@ Its only dependency is Python >= 3.7 (use `python3 -V` to check your version).
## Usage
## Usage
### 1. Extract value of the session cookie
After cloning this repository, follow the following steps to migrate your documents.
 
If you only want to export your visited documents and import them manually, just follow steps 2 and 4.
 
 
### 1. Export Your Owned Documents From Our Codimd Instance and Weed Them Out
 
 
- Go to https://md.inf.tu-dresden.de/
 
- Click on your username in the upper right and hit "*Export user data*"
 
- Download the file "archive.zip" and place it in the same folder as this file (README.md)
 
- **Weed your archive out**! Most likely, it will contain a lot of unused or empty documents. Delete those files in
 
place in the archive, don't extract them.
First of all, you need to extract the value of the `connect.sid` browser cookie for the
### 2. Extract the Value of Your Codimd Session Cookie
 
 
To ensure that the script can access the documents you accessed in our CodiMD instance, you need to extract the value of
 
the `connect.sid` browser cookie for the
particular CodiMD instance that you use (e.g., `md.inf.tu-dresden.de`).
particular CodiMD instance that you use (e.g., `md.inf.tu-dresden.de`).
This procedure is necessary because the CodiMD login is handled externally by Keycloak.
This procedure is necessary because the CodiMD login is handled externally by Keycloak.
@@ -22,38 +53,34 @@ password**. Don't share it with others!
@@ -22,38 +53,34 @@ password**. Don't share it with others!
Now, the instructions are similar for Chrome and Firefox:
Now, the instructions are similar for Chrome and Firefox:
1. Navigate your browser to the CodiMD instance.
1. Navigate your browser to the [CodiMD instance](https://md.inf.tu-dresden.de/). Be sure that you are logged in
2. Open developer tools.
2. Open developer tools (F12).
3. **Chrome**: go to the "Application" tab. **Firefox**: go to the "Storage" tab ("Web-Speicher").
3. **Chrome**: go to the "Application" tab. **Firefox**: go to the "Storage" tab ("Web-Speicher").
4. Un-collapse "Cookies".
4. Un-collapse "Cookies".
5. In the list, search for a cookie with the name `connect.sid`
5. In the list, search for a cookie with the name `connect.sid`
6. Select and copy the value. It must start with the character sequence `s%3A`.
6. Select and copy the value. It must start with the character sequence `s%3A`.
 
### 3. Extract the Value of Your Hedgedoc Session Cookie
 
 
Follow the instructions from step 2, but copy the value of the cookie key `connect.hedgeDoc.sid`
### 2. Execute the script via the command line
### 4. Execute the Script via the Command Line
Clone this repository to a path of your liking and just execute `./codimd_export.py` in a
Execute `./md-import-export.py` or `python3 md-import-export.py` in a
shell. The script will ask for your session id and download the notes to the relative path
shell. The script will ask for your session IDs and download the notes you visited to the relative
`./codimd-documents`.
path `./codimd-documents`.
Please note that your CodiMD history might reference already deleted notes or notes you no
Please note that your CodiMD history might reference already deleted notes or notes you no
longer have access to. The URLs of these inaccessible notes are listed as part of the
longer have access to. The URLs of these inaccessible notes are listed as part of the
script's output.
output of the script.
Furthermore, the script tries to upload every file in the archive with a `.md` extension to our HedgeDoc instance.
### Example
### 5. Visit the Uploaded Documents to Make Them Appear in Your Hedgedoc History
$️ ./codimd_export.py
Please provide your CodiMD session id (connect.sid cookie):
Uploading the documents is not enough to make them appear in your HedgeDoc history.
HTTP 404 Not Found: https://md.inf.tu-dresden.de/TOPofLSB
You need to visit them at least once to make them available.
HTTP 404 Not Found: https://md.inf.tu-dresden.de/6jeKGnJnSp6H0f0mVnBwQQ
The script automatically generates a file `history_scripts/hedgedocu_documents_to_visit.url`.
HTTP 403 Forbidden: https://md.inf.tu-dresden.de/klausur-2020-experiences
You can either visit every file manually or execute the bash script `history_scripts/visit_migrated_documents.sh` (Unix & MacOS).
HTTP 404 Not Found: https://md.inf.tu-dresden.de/iQVB7TO-QXqi3hGSZ7J4Eg
Feel free to contribute a Batch-Script for Windows environments.
HTTP 404 Not Found: https://md.inf.tu-dresden.de/LSB-2020-11-17
Be aware: this might be pretty resource intensive and might take a while.
HTTP 404 Not Found: https://md.inf.tu-dresden.de/Nzbj13ydRLe1d0fRCyG6cA
HTTP 404 Not Found: https://md.inf.tu-dresden.de/LSB-2021-02-02
HTTP 404 Not Found: https://md.inf.tu-dresden.de/LSB-2021-06-22
HTTP 404 Not Found: https://md.inf.tu-dresden.de/LSB-2021-12-07
HTTP 404 Not Found: https://md.inf.tu-dresden.de/ThesisTemplateBachelor
HTTP 404 Not Found: https://md.inf.tu-dresden.de/cnoGl7hoTaK1JIh2-u-h0g
Done: 163 notes successfully downloaded, 11 not accessible.
Loading