Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Added configure_photo_timeout optional argument to upload_photo func
Browse files Browse the repository at this point in the history
And return media info instead bool result
  • Loading branch information
adw0rd committed May 16, 2019
1 parent a547d09 commit 1951b9a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions instabot/api/api.py
Expand Up @@ -312,8 +312,8 @@ def expose(self):
})
return self.send_request('qe/expose/', data)

def upload_photo(self, photo, caption=None, upload_id=None, from_video=False):
return upload_photo(self, photo, caption, upload_id, from_video)
def upload_photo(self, photo, caption=None, upload_id=None, from_video=False, configure_photo_timeout=15):
return upload_photo(self, photo, caption, upload_id, from_video, configure_photo_timeout)

def download_photo(self, media_id, filename, media=False, folder='photos'):
return download_photo(self, media_id, filename, media, folder)
Expand Down
16 changes: 10 additions & 6 deletions instabot/api/api_photo.py
Expand Up @@ -86,7 +86,7 @@ def configure_photo(self, upload_id, photo, caption=''):


def upload_photo(self, photo, caption=None, upload_id=None, from_video=False,
force_rezize=False):
force_rezize=False, configure_photo_timeout=15):
if upload_id is None:
upload_id = str(int(time.time() * 1000))
if not photo:
Expand Down Expand Up @@ -121,11 +121,15 @@ def upload_photo(self, photo, caption=None, upload_id=None, from_video=False,
config.API_URL + "upload/photo/", data=m.to_string())

if response.status_code == 200:
if self.configure_photo(upload_id, photo, caption):
self.expose()
from os import rename
rename(photo, "{}.REMOVE_ME".format(photo))
return True
for attempt in range(4):
if configure_photo_timeout:
time.sleep(configure_photo_timeout)
if self.configure_photo(upload_id, photo, caption):
media = self.last_json.get('media')
self.expose()
from os import rename
rename(photo, "{}.REMOVE_ME".format(photo))
return media
return False


Expand Down
11 changes: 6 additions & 5 deletions instabot/bot/bot_photo.py
Expand Up @@ -6,11 +6,12 @@

def upload_photo(self, photo, caption=None, upload_id=None, from_video=False):
self.small_delay()
if self.api.upload_photo(photo, caption, upload_id, from_video):
self.logger.info("Photo '{}' is uploaded.".format(photo))
return True
self.logger.info("Photo '{}' is not uploaded.".format(photo))
return False
result = self.api.upload_photo(photo, caption, upload_id, from_video)
if not result:
self.logger.info("Photo '{}' is not uploaded.".format(photo))
return False
self.logger.info("Photo '{}' is uploaded.".format(photo))
return result


def download_photo(self, media_id, folder='photos', filename=None, save_description=False):
Expand Down
5 changes: 3 additions & 2 deletions instabot/bot/bot_video.py
Expand Up @@ -4,11 +4,12 @@
def upload_video(self, video, caption='', thumbnail=None):
self.small_delay()
self.logger.info("Started uploading '{video}'".format(video=video))
if not self.api.upload_video(video, caption, thumbnail):
result = self.api.upload_video(video, caption, thumbnail)
if not result:
self.logger.info("Video '%s' is not %s ." % (video, 'uploaded'))
return False
self.logger.info("Video '{video}' uploaded".format(video=video))
return True
return result


def download_video(self, media_id, folder='videos', filename=None, save_description=False):
Expand Down

0 comments on commit 1951b9a

Please sign in to comment.