Skip to content

Instantly share code, notes, and snippets.

@EmadMokhtar
Created May 1, 2019 08:25
Show Gist options
  • Save EmadMokhtar/677a1f72f91d9a5a0268d0fba1ec25ab to your computer and use it in GitHub Desktop.
Save EmadMokhtar/677a1f72f91d9a5a0268d0fba1ec25ab to your computer and use it in GitHub Desktop.
Notion notes sanitizer
import os
current_dir = os.getcwd()
files_extension = ['.md', '.txt', '.docx']
bad_chars = {
'#': 'hash',
'|': '',
'[': '',
']': '',
'?': '',
'&': 'and',
}
files = [f for f in os.listdir(current_dir)
if os.path.isfile(f) and
any([ext for ext in files_extension if ext in f])]
for file in files:
if any(c for c in bad_chars.keys() if c in file):
new_name = file
for k, v in bad_chars.items():
new_name = new_name.replace(k, v)
old_file_path = os.path.join(current_dir, file)
new_file_path = os.path.join(current_dir, new_name)
os.rename(old_file_path, new_file_path)
print(f'Change file name from \n"{file}" name to \n"{new_name}"')
@EmadMokhtar
Copy link
Author

EmadMokhtar commented May 1, 2019

How to run

  • Copy the fix_name.py file to the folder where the notes are located.
  • Open a shell and navigate the note folder.
  • Run python3 fix_name.py.
  • Boom, you can import the note to Notion app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment