Skip to content

Instantly share code, notes, and snippets.

@lokesh1729
Last active January 8, 2024 12:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokesh1729/193375ffee3ae24de928fba5bb5467df to your computer and use it in GitHub Desktop.
Save lokesh1729/193375ffee3ae24de928fba5bb5467df to your computer and use it in GitHub Desktop.
When you export your notion notes, they will be exported with a 32 random character suffix. This script removes them.
import os
import re
import logging
def rename_it(dirpath, path_suffix, is_dir):
pattern = r"([a-zA-Z0-9\s\+\&\']+)\s([a-z0-9]{32})"
match = re.match(pattern, path_suffix)
if match is not None:
if is_dir:
new_name = match.group(1)
else:
new_name = match.group(1) + ".md"
os.rename(os.path.join(dirpath, path_suffix), os.path.join(dirpath, new_name))
logger.info("Successfully renamed from %s to %s", os.path.join(dirpath, path_suffix), os.path.join(dirpath, new_name))
else:
logger.warn("Pattern did not match. Skipping %s", os.path.join(dirpath, path_suffix))
def main():
rename_list = []
for dirpath, dirnames, filenames in os.walk("/Users/lokeshsanapalli/Downloads/2c0de75a-2236-40b6-a838-cb33aab51b9d_Export-84a17067-3e0a-4943-a112-50ea5163285a", topdown=False):
for each_file in filenames:
rename_it(dirpath, each_file, False)
for each_dirname in dirnames:
rename_it(dirpath, each_dirname, True)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment