api.py 文件源码

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

项目:PyMiki 作者: TheGrammarJew 项目源码 文件源码
def build_rtfm_lookup_table(self):
        cache = {}

        page_types = {
            'rewrite': (
                'http://discordpy.rtfd.io/en/rewrite/api.html',
                'http://discordpy.rtfd.io/en/rewrite/ext/commands/api.html'
            ),
            'latest': (
                'http://discordpy.rtfd.io/en/latest/api.html',
            )
        }

        for key, pages in page_types.items():
            sub = cache[key] = {}
            for page in pages:
                async with self.bot.session.get(page) as resp:
                    if resp.status != 200:
                        raise RuntimeError('Cannot build rtfm lookup table, try again later.')

                    text = await resp.text(encoding='utf-8')
                    root = etree.fromstring(text, etree.HTMLParser())
                    nodes = root.findall(".//dt/a[@class='headerlink']")

                    for node in nodes:
                        href = node.get('href', '')
                        as_key = href.replace('#discord.', '').replace('ext.commands.', '')
                        sub[as_key] = page + href

        self._rtfm_cache = cache
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号