added media_category and support for STATUS calls #428

Merged
tushdante merged 4 commits from tushdante-video-upload into master 2016-09-30 04:28:38 -07:00
Showing only changes of commit 7401adfb64 - Show all commits

View file

@ -145,7 +145,7 @@ class EndpointsMixin(object):
"""
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
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.
@ -199,28 +199,33 @@ class EndpointsMixin(object):
'command': 'FINALIZE',
michaelhelmick commented 2016-09-23 06:20:52 -07:00 (Migrated from github.com)

Can you change these double quotes to single quotes, please?

Can you change these double quotes to single quotes, please?
michaelhelmick commented 2016-09-23 06:21:22 -07:00 (Migrated from github.com)

You don't need to default to None as check_after_secs = response_finalize['processing_info'].get('check_after_secs') will return None if it doesn't exist

You don't need to default to `None` as `check_after_secs = response_finalize['processing_info'].get('check_after_secs')` will return `None` if it doesn't exist
michaelhelmick commented 2016-09-23 06:21:37 -07:00 (Migrated from github.com)

You don't need to default to None as processing_state = response_finalize['processing_info'].get('state') will return None if it doesn't exist

You don't need to default to `None` as `processing_state = response_finalize['processing_info'].get('state')` will return `None` if it doesn't exist
michaelhelmick commented 2016-09-26 05:32:34 -07:00 (Migrated from github.com)

Can you just make this if check_progress -- sorry, a lot of the review is just styling issues!

Can you just make this `if check_progress` -- sorry, a lot of the review is just styling issues!
michaelhelmick commented 2016-09-26 05:35:28 -07:00 (Migrated from github.com)

Can you make this:

response = self.post(upload_url, params=params)

outside of this if check_progress:

and use response everywhere you use response_finalize

and outside of the check, you can just return response then, does that make sense or should I elaborate more?

Can you make this: ``` python response = self.post(upload_url, params=params) ``` outside of this `if check_progress:` and use `response` everywhere you use `response_finalize` and outside of the check, you can just `return response` then, does that make sense or should I elaborate more?
tushdante commented 2016-09-26 12:43:49 -07:00 (Migrated from github.com)

No worries! @michaelhelmick totally happy to ensure everything is compliant. appreciate the feedback!

No worries! @michaelhelmick totally happy to ensure everything is compliant. appreciate the feedback!
'media_id': media_id
}
response_finalize = self.post(upload_url, params=params)
# Stage 4: STATUS call if still processing
params = {
'command': 'STATUS',
'media_id': media_id
}
# Only get the status if explicity asked to
# Default to False
if check_progress == True:
processing_state = response_finalize['processing_info'].get('state', None)
response_finalize = self.post(upload_url, params=params)
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)
# Stage 4: STATUS call if still processing
params = {
'command': 'STATUS',
'media_id': media_id
}
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')
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)
michaelhelmick commented 2016-09-23 06:23:26 -07:00 (Migrated from github.com)

Instead of changing the return here, can you add a keyword argument to upload_video like check_progress=False and if they pass check_progress=True, it will execute the code you added, otherwise it will just return the response.

Instead of changing the return here, can you add a keyword argument to `upload_video` like `check_progress=False` and if they pass `check_progress=True`, it will execute the code you added, otherwise it will just return the response.
def get_oembed_tweet(self, **params):
"""Returns information allowing the creation of an embedded