twitter.py 文件源码

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

项目:picdescbot 作者: elad661 项目源码 文件源码
def send(self, picture):
        "Send a tweet. `picture` is a `Result` object from `picdescbot.common`"
        retries = 0
        status = None
        filename = picture.url.split('/')[-1]
        data = picture.download_picture()
        try:
            while retries < 3 and not status:
                if retries > 0:
                    self.log.info('retrying...')
                    data.seek(0)
                try:
                    status = self.api.update_with_media(filename=filename,
                                                        status=picture.caption,
                                                        file=data)
                except tweepy.TweepError as e:
                    self.log.error("Error when sending tweet: %s" % e)
                    retries += 1
                    if retries >= 3:
                        raise
                    else:
                        time.sleep(5)
        finally:
            data.close(really=True)
        return status.id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号