Created
November 26, 2023 12:10
-
-
Save varvir/de45cecb4f6ee28e8a6f8e9a8ad490b9 to your computer and use it in GitHub Desktop.
Python Script that reformat the Notion exported files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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