Add README

This commit is contained in:
Andros Fenollosa 2023-10-29 23:35:22 +01:00
parent 503016694a
commit 2d528c2c87
2 changed files with 60 additions and 6 deletions

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# This script is used to convert a Notion export to a Joplin import (MD - Markdown directory).
## Requirements
- Python 3.6+
## Usage
1. Export your Notion workspace as Markdown & CSV (with subpages) and unzip the archive.
2. Download script.
```bash
curl -O https://github.com/tanrax/notion-to-joplin/raw/main/notion-to-joplin.py
```
3. Run the script:
```bash
python3 notion-to-joplin.py -f <path/to/your/export>
```
Example:
```bash
python3 notion-to-joplin.py -f b25c8352-f87b-4b5b-ce0a-61d09c5bd81b_Export-9e0c6ec4-762b-4d70-b30e-045ece8b4722.zip
```
4. Import the generated folder into Joplin.
You can now import the folder `import to joplin` to Joplin (File > Import > MD - Markdown directory).

View File

@ -1,4 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# This script is used to convert a Notion export to a Joplin import (MD - Markdown directory).
# Step 1: Get the notion export zip file
# Step 2: Unzip the notion export zip file
# Step 3: Rename every file with a .md extension with the heading of the file and fix all the links
# Step 4: Rename all folder. Remove the "hash" from the ending of the folder name and fix all the links
from argparse import ArgumentParser from argparse import ArgumentParser
import sys import sys
import zipfile import zipfile
@ -8,12 +14,6 @@ from os import path
import ntpath import ntpath
import urllib.parse import urllib.parse
# Step 1: Get the notion export zip file
# Step 2: Unzip the notion export zip file
# Step 3: Rename every file with a .md extension with the heading of the file and fix all the links
# Step 4: Rename all folder. Remove the "hash" from the ending of the folder name
# VARIABLES # VARIABLES
FOLDER_EXTRACTION = "import to joplin" FOLDER_EXTRACTION = "import to joplin"
MARKDOWN_EXTENSION = "md" MARKDOWN_EXTENSION = "md"
@ -73,3 +73,26 @@ for filename in glob.iglob(path_to_files, recursive=True):
old_filename_encoded, heading_encoded old_filename_encoded, heading_encoded
) )
file.write(text_to_write) file.write(text_to_write)
print("Renaming files and fixing links done.")
## Step 4: Rename all folder. Remove the "hash" from the ending of the folder name
print("Renaming folders...")
path_of_folders = path.join(FOLDER_EXTRACTION, '**/*')
for folder in glob.iglob(path_of_folders, recursive=True):
if path.isdir(folder):
current_folder_name = path.basename(folder)
new_folder_name = " ".join(current_folder_name.split(" ")[:-1])
shutil.move(folder, path.join(path.dirname(folder), new_folder_name))
# Fix all the links
old_folder_name_encoded = urllib.parse.quote(current_folder_name)
new_folder_name_encoded = urllib.parse.quote(new_folder_name)
for filename_to_fix in glob.iglob(path_to_files, recursive=True):
with open(filename_to_fix, "r") as file:
lines_to_fix = file.readlines()
with open(filename_to_fix, "w") as file:
text_to_write = "".join(lines_to_fix).replace(
old_folder_name_encoded, new_folder_name_encoded
)
file.write(text_to_write)
print("Renaming folders done.")
print("All done. You can now import the folder \"" + FOLDER_EXTRACTION + "\" to Joplin (File > Import > MD - Markdown directory)")