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
评论列表
文章目录