def get_user_matches(name):
"""get_user_matches
Gets the closest name based on the users you have added.
params:
name: str: The name to get the match from.
"""
name = ' '.join(name)
vprint('Attempting to match: "{}"'.format(name), 2)
with open('{}/data.json'.format(FILE_DIR)) as f:
data = f.read()
data = json.loads(data)
if name == '':
return data
names = list(data.keys())
close = difflib.get_close_matches(name, names, 1, 0)
if close == []:
vprint("Uh oh, couldn't find a match. Using '{}'".format(names[0]), 2)
close = names
vprint("I suppose '{}' is close enough.".format(close[0]), 2)
return {close[0]: data[close[0]]}
评论列表
文章目录