yandex_news.py 文件源码

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

项目:sketal 作者: vk-brain 项目源码 文件源码
def process_message(self, msg: Message):
        command, text = self.parse_message(msg)

        if text.lower() in self.help_words:
            return await msg.answer("??????:\n" + "\n".join(self.description) + "\n\n????????? ????:\n" +
                                    ', '.join([k.capitalize() for k in self.news.keys()]))

        url = self.news["???????"]
        if text.lower() in self.news:
            url = self.news[text]

        async with aiohttp.ClientSession() as sess:
            async with sess.get(url) as resp:
                xml = xmltodict.parse(await resp.text())

                if "rss" not in xml or "channel" not in xml["rss"] or "item" not in xml["rss"]["channel"]:
                    return await msg.answer(self.error)

                items = xml["rss"]["channel"]["item"]
                item = choice(items)

                if "title" not in item or "description" not in item:
                    return await msg.answer(self.error)

                return await msg.answer(f'?? {item["title"]}\n'
                                        f'?? {item["description"]}')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号