Skip to content

Instantly share code, notes, and snippets.

@varvir
Created November 26, 2023 12:10
Show Gist options
  • Save varvir/de45cecb4f6ee28e8a6f8e9a8ad490b9 to your computer and use it in GitHub Desktop.
Save varvir/de45cecb4f6ee28e8a6f8e9a8ad490b9 to your computer and use it in GitHub Desktop.
Python Script that reformat the Notion exported files.
# Notion exported filenames looks like the following format.
# "<filename> <hashvalue32>.<ext>"
# Get the filename with string slicing
# Add the contents of file if there is the same filename.
import os, shutil
def removeHashes():
cwd = os.getcwd()
copyto = os.path.join(cwd, 'welldone1')
for file in os.listdir():
if file.endswith('.md'):
print(file + "turn!")
filepath = os.path.join(cwd, file)
newfilepath = os.path.join(copyto, (file[:-36] + file[-3::]))
if os.path.exists(newfilepath):
print(os.path.basename(newfilepath) + "is already exists!")
with open(filepath, mode="rb") as src:
contents = src.read()
with open(newfilepath, mode="ab") as dst:
dst.write(contents)
else:
shutil.copy2(filepath, newfilepath)
print(os.path.basename(newfilepath) + "is copied.")
else:
continue
removeHashes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment