From 2c02b622a2cf8db5a2f060b3cb5672ff4e88d189 Mon Sep 17 00:00:00 2001 From: Tushar Bhushan Date: Wed, 14 Sep 2016 15:35:51 -0700 Subject: [PATCH] added media_category and support for STATUS calls --- twython/endpoints.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/twython/endpoints.py b/twython/endpoints.py index 9fe7734..8814fee 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -199,7 +199,28 @@ class EndpointsMixin(object): 'command': 'FINALIZE', 'media_id': media_id } - return self.post(upload_url, params=params) + response_finalize = self.post(upload_url, params=params) + + # Stage 4: STATUS call if still processing + params = { + 'command': 'STATUS', + 'media_id': media_id + } + + processing_state = response_finalize['processing_info'].get('state', None) + + 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 response_finalize def get_oembed_tweet(self, **params): """Returns information allowing the creation of an embedded