telegram.py 文件源码

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

项目:pycustos 作者: fact-project 项目源码 文件源码
def send_image(self, chat_id, image):
        if isinstance(image, bytes):
            f = BytesIO(image)
            f.seek(0)
            extension = imghdr.what(f)
            self.bot.sendPhoto(chat_id, ('image.' + extension, f))

        elif isinstance(image, str):
            with open(image, 'rb') as f:
                self.bot.sendPhoto(chat_id, f)

        elif hasattr(image, 'read'):
            if hasattr(image, 'name'):
                self.bot.sendPhoto(chat_id, image)
            else:
                self.bot.sendPhoto(chat_id, ('image.png', image))

        else:
            raise TypeError(
                'image needs to be either a filename, bytes or file-like object'
            )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号