parser_functions.py 文件源码

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

项目:spyglass 作者: Crypta-Eve 项目源码 文件源码
def parseShips(rtext):
    def formatShipName(text, word):
        newText = u"""<span style="color:#d95911;font-weight:bold"> {0}</span>"""
        text = text.replace(word, newText.format(word))
        return text

    texts = [t for t in rtext.contents if isinstance(t, NavigableString)]
    for text in texts:
        upperText = text.upper()
        for shipName in evegate.SHIPNAMES:
            if shipName in upperText:
                hit = True
                start = upperText.find(shipName)
                end = start + len(shipName)
                if ((start > 0 and upperText[start - 1] not in (" ", "X")) or (
                                end < len(upperText) - 1 and upperText[end] not in ("S", " "))):
                    hit = False
                if hit:
                    shipInText = text[start:end]
                    formatted = formatShipName(text, shipInText)
                    textReplace(text, formatted)
                    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号