checkwiki.py 文件源码

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

项目:NapalmBot 作者: Facenapalm 项目源码 文件源码
def error_068_interwiki_link(text):
    """
    Fix links to Special:BookSearch and direct links, written like interwiki
    ones. For example, for ruwiki fixes [[:ru:Example|Something]].
    Return (new_text, replacements_count) tuple.
    """
    def _check_link(match_obj):
        """Check if founded link is a link to a file or a category and insert extra ":" if so."""
        link = match_obj.group(2).lstrip().lower()
        if re.search(r"^" + IMAGE, link) is None and re.search(r"^" + CATEGORY, link) is None:
            return match_obj.group(1) + match_obj.group(2)
        else:
            return match_obj.group(1) + ":" + match_obj.group(2)

    # bot will not fix links without a pipe: manual control needed
    (text, direct) = re.subn(r"(\[\[):{}:([^|\[\]\n]+\|[^|\[\]\n]+\]\])".format(LANG_CODE),
                             _check_link, text, flags=re.I)
    (text, books) = re.subn(r"\[\[:..:Special:BookSources/\d+X?\|(ISBN [0-9\-X]+)\]\]",
                            "\\1", text, flags=re.I)
    return (text, direct + books)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号