program.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:youtube_watcher 作者: Sjc1000 项目源码 文件源码
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]]}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号