Created
December 31, 2020 14:32
-
-
Save x100ex/10f260499e62f69a717484b5e4386b4f to your computer and use it in GitHub Desktop.
Zettelkasten identifiers uniqueness check
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
#!/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