thx.py 文件源码

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

项目:beproudbot 作者: beproud 项目源码 文件源码
def find_thx(s, text):
    """Slack?????????????thx???????

    :param s: sqlalchemy.orm.session.Session
    :param str text: ???????????
    :return dict word_map_names_dict:
       ???thx??????????Slack????????
    :return list hint_names: Slack??????????????????
    :return list not_matched: Slack???????????????????
    """
    word_map_names_dict = {}
    hint_names = []
    not_matched = []

    thx_matcher = re.compile('(?P<user_names>.+)[ \t\f\v]*\+\+[ \t\f\v]+(?P<word>.+)',
                             re.MULTILINE)
    for thx in thx_matcher.finditer(text):
        user_names = [x for x in thx.group('user_names').split(' ') if x]
        for name in user_names:
            if get_user_name(name.lstrip('<@').rstrip('>')):
                slack_id = name.lstrip('<@').rstrip('>')
            else:
                slack_id = get_slack_id(s, name)

            if slack_id:
                word_map_names_dict.setdefault(
                    thx.group('word'), []
                ).append((slack_id, name))
            else:
                # ????????????
                hint = get_close_matches(name, get_users_info().values())
                if hint:
                    hint_names.append(hint[0])
                # ?????????????????
                else:
                    not_matched.append(name)

    return word_map_names_dict, hint_names, not_matched
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号