Games.py 文件源码

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

项目:paobot-Release 作者: cjoeml 项目源码 文件源码
def hots_free(self, ctx):
            """Retrieves the Heroes of the Storm free rotation."""
            url = "http://us.battle.net/heroes/en/"
            soup = BeautifulSoup(urlopen(url), 'html5lib')
            parsedText = [] ## End result: finds cleaned text from HTML
            freeHeroes = [] ## Index of all free heroes found 

            freeIndicator = "|| Free" ## This is what Blizzard uses to indicate free heroes in their webpage
            for elem in soup.find_all('li'):
                if "free-rotation" in str(elem):
                    index = str(elem).find(freeIndicator)
                    ## General area of where the string needed is. I'm lazy. ##
                    parsedText.append(str(elem)[index-100:index+100])

            ## Find text via regex ##
            for string in parsedText:
                result = re.search('data-analytics-placement="(.*) Free"', string)
                freeHeroes.append(result.group(1)[0:-3])

            ## Formats via Discord's markdown ##
            botText = "```md\n<Free-Rotation>```" + "```"
            for hero in freeHeroes:
                botText += hero+", "
            botText = botText[0:-2] + "```"
            await self.bot.say(botText)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号