Skip to content

Instantly share code, notes, and snippets.

@tiagolr
Created July 13, 2022 09:48
Show Gist options
  • Save tiagolr/0a3d8d4c609bfe97b95d7e70dbf4541b to your computer and use it in GitHub Desktop.
Save tiagolr/0a3d8d4c609bfe97b95d7e70dbf4541b to your computer and use it in GitHub Desktop.
fuzzy search files
'''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