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
评论列表
文章目录