Created
July 13, 2022 09:48
-
-
Save tiagolr/0a3d8d4c609bfe97b95d7e70dbf4541b to your computer and use it in GitHub Desktop.
fuzzy search 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
'''Fuzzy search zim notes''' | |
import os | |
import glob | |
import sys | |
from fuzzywuzzy import fuzz | |
files = [] | |
notespath = 'C:\\' | |
zimpath = 'C:\\' | |
search = ' '.join(sys.argv[1:]) | |
for f in glob.iglob(notespath + '/**/*.txt', recursive=True): | |
split = f[len(notespath) + 1:].split('\\') | |
ratio = fuzz.ratio(split[-1].lower(), search.lower()) | |
split.append(ratio) | |
files.append(split) | |
match = sorted(files, key=lambda x: x[-1]).pop() | |
notename = ':'.join(match[:-1])[:-4] | |
os.system(zimpath + ' ' + notename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment