Skip to content

Instantly share code, notes, and snippets.

@x100ex
Created December 31, 2020 14:32
Show Gist options
  • Save x100ex/10f260499e62f69a717484b5e4386b4f to your computer and use it in GitHub Desktop.
Save x100ex/10f260499e62f69a717484b5e4386b4f to your computer and use it in GitHub Desktop.
Zettelkasten identifiers uniqueness check
#!/usr/bin/env python3
# Zettelkasten identifiers uniqueness check
import os, pathlib, re
"""
Find and print non-unique Zettelkasten identifiers
"""
def find_and_print_nnuqzkid(workdir):
zk_map = {}
questionable_files = []
for p in pathlib.Path(workdir).iterdir():
if p.is_file() and p.suffix.casefold() == '.TXT'.casefold():
m = re.match(r'^[0-9]+\s', str(p.name))
if m:
id = m[0]
if id in zk_map:
zk_map[id].append(p)
else:
zk_map[id] = [p]
else:
questionable_files.append(p)
if len(questionable_files) > 0:
print("Questionable files are found:")
for p2 in questionable_files:
print(" - \"" + str(p2.name) + "\"")
count = 1
for p in zk_map.items():
if len(p[1]) > 1:
print("Zettelkasten ID dublicates are found (#" + str(count) + "):")
count += 1
for p2 in p[1]:
print(" - \"" + str(p2.name) + "\"")
find_and_print_nnuqzkid(os.getcwd())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment