- Double -> single quotes

- Removed default value from .get()
- Added a check_progress param to upload_video to allow users to decide when to check 'STATUS' calls
This commit is contained in:
Tushar Bhushan 2016-09-25 18:03:26 -07:00
parent 2c02b622a2
commit 7401adfb64

View file

@ -145,7 +145,7 @@ class EndpointsMixin(object):
""" """
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
def upload_video(self, media, media_type, size=None): def upload_video(self, media, media_type, size=None, check_progress=False):
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached """Uploads video file to Twitter servers in chunks. The file will be available to be attached
to a status for 60 minutes. To attach to a update, pass a list of returned media ids to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the 'update_status' method using the 'media_ids' param. to the 'update_status' method using the 'media_ids' param.
@ -199,28 +199,33 @@ class EndpointsMixin(object):
'command': 'FINALIZE', 'command': 'FINALIZE',
'media_id': media_id 'media_id': media_id
} }
response_finalize = self.post(upload_url, params=params)
# Stage 4: STATUS call if still processing # Only get the status if explicity asked to
params = { # Default to False
'command': 'STATUS', if check_progress == True:
'media_id': media_id
}
processing_state = response_finalize['processing_info'].get('state', None)
if processing_state is not None: response_finalize = self.post(upload_url, params=params)
while (processing_state == "pending" or processing_state == "in_progress") :
# get the secs to wait
check_after_secs = response_finalize['processing_info'].get('check_after_secs', None)
if check_after_secs is not None: # Stage 4: STATUS call if still processing
time.sleep(check_after_secs) params = {
response_finalize = self.get(upload_url, params=params) 'command': 'STATUS',
# get new state after waiting 'media_id': media_id
processing_state = response_finalize['processing_info'].get('state') }
processing_state = response_finalize['processing_info'].get('state')
return response_finalize if processing_state is not None:
while (processing_state == 'pending' or processing_state == 'in_progress') :
# get the secs to wait
check_after_secs = response_finalize['processing_info'].get('check_after_secs', None)
if check_after_secs is not None:
time.sleep(check_after_secs)
response_finalize = self.get(upload_url, params=params)
# get new state after waiting
processing_state = response_finalize['processing_info'].get('state')
return self.post(upload_url, param=params)
def get_oembed_tweet(self, **params): def get_oembed_tweet(self, **params):
"""Returns information allowing the creation of an embedded """Returns information allowing the creation of an embedded