From 9c3fa65868ad15e54f2a8265bd9396ada98bbe97 Mon Sep 17 00:00:00 2001 From: Harmon Date: Mon, 26 Aug 2019 23:30:12 -0500 Subject: [PATCH] Improve API formatting Also fix missing quotation marks in allowed parameters and improve capitalization in docstrings --- tweepy/api.py | 388 +++++++++++++++++++++++++++++--------------------- 1 file changed, 223 insertions(+), 165 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index fc38124..0dcc843 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -23,25 +23,33 @@ class API(object): retry_delay=0, retry_errors=None, timeout=60, parser=None, compression=False, wait_on_rate_limit=False, wait_on_rate_limit_notify=False, proxy=''): - """ Api instance Constructor + """ + API instance constructor :param auth_handler: - :param host: url of the server of the rest api, default:'api.twitter.com' - :param search_host: url of the search server, default:'search.twitter.com' - :param upload_host: url of the upload server, default:'upload.twitter.com' - :param cache: Cache to query if a GET method is used, default:None - :param api_root: suffix of the api version, default:'/1.1' - :param search_root: suffix of the search version, default:'' - :param upload_root: suffix of the upload version, default:'/1.1' - :param retry_count: number of allowed retries, default:0 - :param retry_delay: delay in second between retries, default:0 - :param retry_errors: default:None - :param timeout: delay before to consider the request as timed out in seconds, default:60 - :param parser: ModelParser instance to parse the responses, default:None - :param compression: If the response is compressed, default:False - :param wait_on_rate_limit: If the api wait when it hits the rate limit, default:False - :param wait_on_rate_limit_notify: If the api print a notification when the rate limit is hit, default:False - :param proxy: Url to use as proxy during the HTTP request, default:'' + :param host: url of the server of the rest api, + default: 'api.twitter.com' + :param search_host: url of the search server, + default: 'search.twitter.com' + :param upload_host: url of the upload server, + default: 'upload.twitter.com' + :param cache: Cache to query if a GET method is used, default: None + :param api_root: suffix of the api version, default: '/1.1' + :param search_root: suffix of the search version, default: '' + :param upload_root: suffix of the upload version, default: '/1.1' + :param retry_count: number of allowed retries, default: 0 + :param retry_delay: delay in second between retries, default: 0 + :param retry_errors: default: None + :param timeout: delay before to consider the request as timed out in + seconds, default: 60 + :param parser: ModelParser instance to parse the responses, + default: None + :param compression: If the response is compressed, default: False + :param wait_on_rate_limit: If the api wait when it hits the rate limit, + default: False + :param wait_on_rate_limit_notify: If the api print a notification when + the rate limit is hit, default: False + :param proxy: Url to use as proxy during the HTTP request, default: '' :raise TypeError: If the given parser is not a ModelParser instance. """ @@ -67,7 +75,7 @@ class API(object): # Attempt to explain more clearly the parser argument requirements # https://github.com/tweepy/tweepy/issues/421 - # + parser_type = Parser if not isinstance(self.parser, parser_type): raise TypeError( @@ -81,7 +89,7 @@ class API(object): @property def home_timeline(self): """ :reference: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline - :allowed_param:'since_id', 'max_id', 'count' + :allowed_param: 'since_id', 'max_id', 'count' """ return bind_api( api=self, @@ -91,28 +99,32 @@ class API(object): require_auth=True ) - def statuses_lookup(self, id_, include_entities=None, - trim_user=None, map_=None, tweet_mode=None): + def statuses_lookup(self, id_, include_entities=None, trim_user=None, + map_=None, tweet_mode=None): return self._statuses_lookup(list_to_csv(id_), include_entities, trim_user, map_, tweet_mode) @property def _statuses_lookup(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-lookup - :allowed_param:'id', 'include_entities', 'trim_user', 'map', 'tweet_mode' + :allowed_param: 'id', 'include_entities', 'trim_user', 'map', + 'tweet_mode' """ return bind_api( api=self, path='/statuses/lookup.json', payload_type='status', payload_list=True, - allowed_param=['id', 'include_entities', 'trim_user', 'map', 'tweet_mode'], + allowed_param=['id', 'include_entities', 'trim_user', 'map', + 'tweet_mode'], require_auth=True ) @property def user_timeline(self): """ :reference: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline - :allowed_param:'id', 'user_id', 'screen_name', 'since_id', 'max_id', 'count', 'include_rts', 'trim_user', 'exclude_replies' + :allowed_param: 'id', 'user_id', 'screen_name', 'since_id', + 'max_id', 'count', 'include_rts', 'trim_user', + 'exclude_replies' """ return bind_api( api=self, @@ -126,7 +138,7 @@ class API(object): @property def mentions_timeline(self): """ :reference: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-mentions_timeline - :allowed_param:'since_id', 'max_id', 'count' + :allowed_param: 'since_id', 'max_id', 'count' """ return bind_api( api=self, @@ -139,7 +151,7 @@ class API(object): @property def related_results(self): """ :reference: https://dev.twitter.com/docs/api/1.1/get/related_results/show/%3id.format - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -152,7 +164,7 @@ class API(object): @property def retweets_of_me(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets_of_me - :allowed_param:'since_id', 'max_id', 'count' + :allowed_param: 'since_id', 'max_id', 'count' """ return bind_api( api=self, @@ -165,7 +177,7 @@ class API(object): @property def get_status(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -176,7 +188,12 @@ class API(object): def update_status(self, *args, **kwargs): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update - :allowed_param:'status', 'in_reply_to_status_id', 'auto_populate_reply_metadata', 'exclude_reply_user_ids', 'attachment_url', 'media_ids', 'possibly_sensitive', 'lat', 'long', 'place_id', 'display_coordinates', 'trim_user', 'enable_dmcommands', 'fail_dmcommands', 'card_uri' + :allowed_param: 'status', 'in_reply_to_status_id', + 'auto_populate_reply_metadata', + 'exclude_reply_user_ids', 'attachment_url', + 'media_ids', 'possibly_sensitive', 'lat', 'long', + 'place_id', 'display_coordinates', 'trim_user', + 'enable_dmcommands', 'fail_dmcommands', 'card_uri' """ post_data = {} media_ids = kwargs.pop("media_ids", None) @@ -188,7 +205,13 @@ class API(object): path='/statuses/update.json', method='POST', payload_type='status', - allowed_param=['status', 'in_reply_to_status_id', 'auto_populate_reply_metadata', 'exclude_reply_user_ids', 'attachment_url', 'media_ids', 'possibly_sensitive', 'lat', 'long', 'place_id', 'display_coordinates', 'trim_user', 'enable_dmcommands', 'fail_dmcommands', 'card_uri'], + allowed_param=['status', 'in_reply_to_status_id', + 'auto_populate_reply_metadata', + 'exclude_reply_user_ids', 'attachment_url', + 'media_ids', 'possibly_sensitive', 'lat', 'long', + 'place_id', 'display_coordinates', 'trim_user', + 'enable_dmcommands', 'fail_dmcommands', + 'card_uri'], require_auth=True )(post_data=post_data, *args, **kwargs) @@ -197,7 +220,8 @@ class API(object): :allowed_param: """ f = kwargs.pop('file', None) - headers, post_data = API._pack_image(filename, 4883, form_field='media', f=f) + headers, post_data = API._pack_image(filename, 4883, + form_field='media', f=f) kwargs.update({'headers': headers, 'post_data': post_data}) return bind_api( @@ -212,10 +236,15 @@ class API(object): def update_with_media(self, filename, *args, **kwargs): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update_with_media - :allowed_param:'status', 'possibly_sensitive', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'auto_populate_reply_metadata', 'lat', 'long', 'place_id', 'display_coordinates' + :allowed_param: 'status', 'possibly_sensitive', + 'in_reply_to_status_id', + 'in_reply_to_status_id_str', + 'auto_populate_reply_metadata', 'lat', 'long', + 'place_id', 'display_coordinates' """ f = kwargs.pop('file', None) - headers, post_data = API._pack_image(filename, 3072, form_field='media[]', f=f) + headers, post_data = API._pack_image(filename, 3072, + form_field='media[]', f=f) kwargs.update({'headers': headers, 'post_data': post_data}) return bind_api( @@ -223,17 +252,18 @@ class API(object): path='/statuses/update_with_media.json', method='POST', payload_type='status', - allowed_param=[ - 'status', 'possibly_sensitive', 'in_reply_to_status_id', 'in_reply_to_status_id_str', - 'auto_populate_reply_metadata', 'lat', 'long', 'place_id', 'display_coordinates' - ], + allowed_param=['status', 'possibly_sensitive', + 'in_reply_to_status_id', + 'in_reply_to_status_id_str', + 'auto_populate_reply_metadata', 'lat', 'long', + 'place_id', 'display_coordinates'], require_auth=True )(*args, **kwargs) @property def destroy_status(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-destroy-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -247,7 +277,7 @@ class API(object): @property def retweet(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -261,7 +291,7 @@ class API(object): @property def unretweet(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-unretweet-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -275,7 +305,7 @@ class API(object): @property def retweets(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweets-id - :allowed_param:'id', 'count' + :allowed_param: 'id', 'count' """ return bind_api( api=self, @@ -288,7 +318,7 @@ class API(object): @property def retweeters(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-retweeters-ids - :allowed_param:'id', 'cursor', 'stringify_ids + :allowed_param: 'id', 'cursor', 'stringify_ids """ return bind_api( api=self, @@ -300,7 +330,7 @@ class API(object): @property def get_user(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -312,16 +342,19 @@ class API(object): @property def get_oembed(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed - :allowed_param:'id', 'url', 'maxwidth', 'hide_media', 'omit_script', 'align', 'related', 'lang' + :allowed_param: 'id', 'url', 'maxwidth', 'hide_media', + 'omit_script', 'align', 'related', 'lang' """ return bind_api( api=self, path='/statuses/oembed.json', payload_type='json', - allowed_param=['id', 'url', 'maxwidth', 'hide_media', 'omit_script', 'align', 'related', 'lang'] + allowed_param=['id', 'url', 'maxwidth', 'hide_media', + 'omit_script', 'align', 'related', 'lang'] ) - def lookup_users(self, user_ids=None, screen_names=None, include_entities=None, tweet_mode=None): + def lookup_users(self, user_ids=None, screen_names=None, + include_entities=None, tweet_mode=None): """ Perform bulk look up of users from user ID or screen_name """ post_data = {} if include_entities is not None: @@ -339,14 +372,16 @@ class API(object): @property def _lookup_users(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup - allowed_param='user_id', 'screen_name', 'include_entities', 'tweet_mode' + allowed_param= 'user_id', 'screen_name', 'include_entities', + 'tweet_mode' """ return bind_api( api=self, path='/users/lookup.json', payload_type='user', payload_list=True, method='POST', - allowed_param=['user_id', 'screen_name', 'include_entities', 'tweet_mode'] + allowed_param=['user_id', 'screen_name', 'include_entities', + 'tweet_mode'] ) def me(self): @@ -356,7 +391,7 @@ class API(object): @property def search_users(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search - :allowed_param:'q', 'count', 'page' + :allowed_param: 'q', 'count', 'page' """ return bind_api( api=self, @@ -369,7 +404,7 @@ class API(object): @property def get_direct_message(self): """ :reference: https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -382,7 +417,7 @@ class API(object): @property def list_direct_messages(self): """ :reference: https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events - :allowed_param:'count', 'cursor' + :allowed_param: 'count', 'cursor' """ return bind_api( api=self, @@ -392,36 +427,48 @@ class API(object): require_auth=True ) - def send_direct_message(self, recipient_id, text, quick_reply_type=None, attachment_type=None, attachment_media_id=None): - """ Send a direct message to the specified user from the authenticating user """ - json_payload = {'event': {'type': 'message_create', 'message_create': {'target': {'recipient_id': recipient_id}}}} - json_payload['event']['message_create']['message_data'] = {'text': text} + def send_direct_message(self, recipient_id, text, quick_reply_type=None, + attachment_type=None, attachment_media_id=None): + """ + Send a direct message to the specified user from the authenticating + user + """ + json_payload = { + 'event': {'type': 'message_create', + 'message_create': { + 'target': {'recipient_id': recipient_id}, + 'message_data': {'text': text} + } + } + } + message_data = json_payload['event']['message_create']['message_data'] if quick_reply_type is not None: - json_payload['event']['message_create']['message_data']['quick_reply'] = {'type': quick_reply_type} + message_data['quick_reply'] = {'type': quick_reply_type} if attachment_type is not None and attachment_media_id is not None: - json_payload['event']['message_create']['message_data']['attachment'] = {'type': attachment_type} - json_payload['event']['message_create']['message_data']['attachment']['media'] = {'id': attachment_media_id} - + message_data['attachment'] = {'type': attachment_type} + message_data['attachment']['media'] = {'id': attachment_media_id} return self._send_direct_message(json_payload=json_payload) @property def _send_direct_message(self): """ :reference: https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event - :allowed_param:'recipient_id', 'text', 'quick_reply_type', 'attachment_type', attachment_media_id' + :allowed_param: 'recipient_id', 'text', 'quick_reply_type', + 'attachment_type', attachment_media_id' """ return bind_api( api=self, path='/direct_messages/events/new.json', method='POST', payload_type='direct_message', - allowed_param=['recipient_id', 'text', 'quick_reply_type', 'attachment_type', 'attachment_media_id'], + allowed_param=['recipient_id', 'text', 'quick_reply_type', + 'attachment_type', 'attachment_media_id'], require_auth=True ) @property def destroy_direct_message(self): """ :reference: https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message-event - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -434,7 +481,7 @@ class API(object): @property def create_friendship(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create - :allowed_param:'id', 'user_id', 'screen_name', 'follow' + :allowed_param: 'id', 'user_id', 'screen_name', 'follow' """ return bind_api( api=self, @@ -448,7 +495,7 @@ class API(object): @property def destroy_friendship(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-destroy - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -462,7 +509,8 @@ class API(object): @property def show_friendship(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show - :allowed_param:'source_id', 'source_screen_name', 'target_id', 'target_screen_name' + :allowed_param: 'source_id', 'source_screen_name', 'target_id', + 'target_screen_name' """ return bind_api( api=self, @@ -474,12 +522,13 @@ class API(object): def lookup_friendships(self, user_ids=None, screen_names=None): """ Perform bulk look up of friendships from user ID or screenname """ - return self._lookup_friendships(list_to_csv(user_ids), list_to_csv(screen_names)) + return self._lookup_friendships(list_to_csv(user_ids), + list_to_csv(screen_names)) @property def _lookup_friendships(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-lookup - :allowed_param:'user_id', 'screen_name' + :allowed_param: 'user_id', 'screen_name' """ return bind_api( api=self, @@ -492,7 +541,7 @@ class API(object): @property def friends_ids(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids - :allowed_param:'id', 'user_id', 'screen_name', 'cursor' + :allowed_param: 'id', 'user_id', 'screen_name', 'cursor' """ return bind_api( api=self, @@ -504,19 +553,21 @@ class API(object): @property def friends(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-list - :allowed_param:'id', 'user_id', 'screen_name', 'cursor', 'count', 'skip_status', 'include_user_entities' + :allowed_param: 'id', 'user_id', 'screen_name', 'cursor', 'count', + 'skip_status', 'include_user_entities' """ return bind_api( api=self, path='/friends/list.json', payload_type='user', payload_list=True, - allowed_param=['id', 'user_id', 'screen_name', 'cursor', 'count', 'skip_status', 'include_user_entities'] + allowed_param=['id', 'user_id', 'screen_name', 'cursor', 'count', + 'skip_status', 'include_user_entities'] ) @property def friendships_incoming(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming - :allowed_param:'cursor' + :allowed_param: 'cursor' """ return bind_api( api=self, @@ -528,7 +579,7 @@ class API(object): @property def friendships_outgoing(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-outgoing - :allowed_param:'cursor' + :allowed_param: 'cursor' """ return bind_api( api=self, @@ -540,7 +591,7 @@ class API(object): @property def followers_ids(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids - :allowed_param:'id', 'user_id', 'screen_name', 'cursor', 'count' + :allowed_param: 'id', 'user_id', 'screen_name', 'cursor', 'count' """ return bind_api( api=self, @@ -552,7 +603,8 @@ class API(object): @property def followers(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-list - :allowed_param:'id', 'user_id', 'screen_name', 'cursor', 'count', 'skip_status', 'include_user_entities' + :allowed_param: 'id', 'user_id', 'screen_name', 'cursor', 'count', + 'skip_status', 'include_user_entities' """ return bind_api( api=self, @@ -575,9 +627,10 @@ class API(object): @property def set_settings(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-settings - :allowed_param:'sleep_time_enabled', 'start_sleep_time', - 'end_sleep_time', 'time_zone', 'trend_location_woeid', - 'allow_contributor_request', 'lang' + :allowed_param: 'sleep_time_enabled', 'start_sleep_time', + 'end_sleep_time', 'time_zone', + 'trend_location_woeid', + 'allow_contributor_request', 'lang' """ return bind_api( api=self, @@ -586,14 +639,14 @@ class API(object): payload_type='json', allowed_param=['sleep_time_enabled', 'start_sleep_time', 'end_sleep_time', 'time_zone', - 'trend_location_woeid', 'allow_contributor_request', - 'lang'], + 'trend_location_woeid', + 'allow_contributor_request', 'lang'], use_cache=False ) def verify_credentials(self, **kwargs): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials - :allowed_param:'include_entities', 'skip_status', 'include_email' + :allowed_param: 'include_entities', 'skip_status', 'include_email' """ try: return bind_api( @@ -601,7 +654,8 @@ class API(object): path='/account/verify_credentials.json', payload_type='user', require_auth=True, - allowed_param=['include_entities', 'skip_status', 'include_email'], + allowed_param=['include_entities', 'skip_status', + 'include_email'], )(**kwargs) except TweepError as e: if e.response and e.response.status == 401: @@ -611,7 +665,7 @@ class API(object): @property def rate_limit_status(self): """ :reference: https://developer.twitter.com/en/docs/developer-utilities/rate-limit-status/api-reference/get-application-rate_limit_status - :allowed_param:'resources' + :allowed_param: 'resources' """ return bind_api( api=self, @@ -623,7 +677,7 @@ class API(object): def update_profile_image(self, filename, file_=None): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image - :allowed_param:'include_entities', 'skip_status' + :allowed_param: 'include_entities', 'skip_status' """ headers, post_data = API._pack_image(filename, 700, f=file_) return bind_api( @@ -637,7 +691,7 @@ class API(object): def update_profile_background_image(self, filename, **kwargs): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_background_image - :allowed_param:'tile', 'include_entities', 'skip_status', 'use' + :allowed_param: 'tile', 'include_entities', 'skip_status', 'use' """ f = kwargs.pop('file', None) headers, post_data = API._pack_image(filename, 800, f=f) @@ -652,10 +706,11 @@ class API(object): def update_profile_banner(self, filename, **kwargs): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner - :allowed_param:'width', 'height', 'offset_left', 'offset_right' + :allowed_param: 'width', 'height', 'offset_left', 'offset_right' """ f = kwargs.pop('file', None) - headers, post_data = API._pack_image(filename, 700, form_field="banner", f=f) + headers, post_data = API._pack_image(filename, 700, + form_field="banner", f=f) return bind_api( api=self, path='/account/update_profile_banner.json', @@ -667,33 +722,37 @@ class API(object): @property def update_profile(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile - :allowed_param:'name', 'url', 'location', 'description', 'profile_link_color' + :allowed_param: 'name', 'url', 'location', 'description', + 'profile_link_color' """ return bind_api( api=self, path='/account/update_profile.json', method='POST', payload_type='user', - allowed_param=['name', 'url', 'location', 'description', 'profile_link_color'], + allowed_param=['name', 'url', 'location', 'description', + 'profile_link_color'], require_auth=True ) @property def favorites(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-favorites-list - :allowed_param:'screen_name', 'user_id', 'max_id', 'count', 'since_id', 'max_id' + :allowed_param: 'screen_name', 'user_id', 'max_id', 'count', + 'since_id', 'max_id' """ return bind_api( api=self, path='/favorites/list.json', payload_type='status', payload_list=True, - allowed_param=['screen_name', 'user_id', 'max_id', 'count', 'since_id', 'max_id'] + allowed_param=['screen_name', 'user_id', 'max_id', 'count', + 'since_id', 'max_id'] ) @property def create_favorite(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-create - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -707,7 +766,7 @@ class API(object): @property def destroy_favorite(self): """ :reference: https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-favorites-destroy - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -721,7 +780,7 @@ class API(object): @property def create_block(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-blocks-create - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -735,7 +794,7 @@ class API(object): @property def destroy_block(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-blocks-destroy - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -749,7 +808,7 @@ class API(object): @property def mutes_ids(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-ids - :allowed_param:'cursor' + :allowed_param: 'cursor' """ return bind_api( api=self, @@ -776,7 +835,7 @@ class API(object): @property def create_mute(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-create - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -790,7 +849,7 @@ class API(object): @property def destroy_mute(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-mutes-users-destroy - :allowed_param:'id', 'user_id', 'screen_name' + :allowed_param: 'id', 'user_id', 'screen_name' """ return bind_api( api=self, @@ -804,7 +863,7 @@ class API(object): @property def blocks(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-blocks-list - :allowed_param:'cursor' + :allowed_param: 'cursor' """ return bind_api( api=self, @@ -817,7 +876,7 @@ class API(object): @property def blocks_ids(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-blocks-ids - :allowed_param:'cursor' + :allowed_param: 'cursor' """ return bind_api( api=self, @@ -830,7 +889,7 @@ class API(object): @property def report_spam(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/post-users-report_spam - :allowed_param:'user_id', 'screen_name', 'perform_block' + :allowed_param: 'user_id', 'screen_name', 'perform_block' """ return bind_api( api=self, @@ -854,7 +913,7 @@ class API(object): @property def get_saved_search(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-show-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -867,7 +926,7 @@ class API(object): @property def create_saved_search(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-create - :allowed_param:'query' + :allowed_param: 'query' """ return bind_api( api=self, @@ -881,7 +940,7 @@ class API(object): @property def destroy_saved_search(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-saved_searches-destroy-id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -895,7 +954,7 @@ class API(object): @property def create_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-create - :allowed_param:'name', 'mode', 'description' + :allowed_param: 'name', 'mode', 'description' """ return bind_api( api=self, @@ -909,7 +968,7 @@ class API(object): @property def destroy_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy - :allowed_param:'owner_screen_name', 'owner_id', 'list_id', 'slug' + :allowed_param: 'owner_screen_name', 'owner_id', 'list_id', 'slug' """ return bind_api( api=self, @@ -923,21 +982,23 @@ class API(object): @property def update_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-update - :allowed_param: list_id', 'slug', 'name', 'mode', 'description', 'owner_screen_name', 'owner_id' + :allowed_param: 'list_id', 'slug', 'name', 'mode', 'description', + 'owner_screen_name', 'owner_id' """ return bind_api( api=self, path='/lists/update.json', method='POST', payload_type='list', - allowed_param=['list_id', 'slug', 'name', 'mode', 'description', 'owner_screen_name', 'owner_id'], + allowed_param=['list_id', 'slug', 'name', 'mode', 'description', + 'owner_screen_name', 'owner_id'], require_auth=True ) @property def lists_all(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-list - :allowed_param:'screen_name', 'user_id' + :allowed_param: 'screen_name', 'user_id' """ return bind_api( api=self, @@ -950,20 +1011,22 @@ class API(object): @property def lists_memberships(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships - :allowed_param:'screen_name', 'user_id', 'filter_to_owned_lists', 'cursor' + :allowed_param: 'screen_name', 'user_id', 'filter_to_owned_lists', + 'cursor' """ return bind_api( api=self, path='/lists/memberships.json', payload_type='list', payload_list=True, - allowed_param=['screen_name', 'user_id', 'filter_to_owned_lists', 'cursor'], + allowed_param=['screen_name', 'user_id', 'filter_to_owned_lists', + 'cursor'], require_auth=True ) @property def lists_subscriptions(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions - :allowed_param:'screen_name', 'user_id', 'cursor' + :allowed_param: 'screen_name', 'user_id', 'cursor' """ return bind_api( api=self, @@ -976,22 +1039,21 @@ class API(object): @property def list_timeline(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses - :allowed_param:'owner_screen_name', 'slug', 'owner_id', 'list_id', - 'since_id', 'max_id', 'count', 'include_rts + :allowed_param: 'owner_screen_name', 'slug', 'owner_id', 'list_id', + 'since_id', 'max_id', 'count', 'include_rts """ return bind_api( api=self, path='/lists/statuses.json', payload_type='status', payload_list=True, - allowed_param=['owner_screen_name', 'slug', 'owner_id', - 'list_id', 'since_id', 'max_id', 'count', - 'include_rts'] + allowed_param=['owner_screen_name', 'slug', 'owner_id', 'list_id', + 'since_id', 'max_id', 'count', 'include_rts'] ) @property def get_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-show - :allowed_param:'owner_screen_name', 'owner_id', 'slug', 'list_id' + :allowed_param: 'owner_screen_name', 'owner_id', 'slug', 'list_id' """ return bind_api( api=self, @@ -1003,8 +1065,8 @@ class API(object): @property def add_list_member(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create - :allowed_param:'screen_name', 'user_id', 'owner_screen_name', - 'owner_id', 'slug', 'list_id' + :allowed_param: 'screen_name', 'user_id', 'owner_screen_name', + 'owner_id', 'slug', 'list_id' """ return bind_api( api=self, @@ -1019,8 +1081,8 @@ class API(object): @property def remove_list_member(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy - :allowed_param:'screen_name', 'user_id', 'owner_screen_name', - 'owner_id', 'slug', 'list_id' + :allowed_param: 'screen_name', 'user_id', 'owner_screen_name', + 'owner_id', 'slug', 'list_id' """ return bind_api( api=self, @@ -1036,16 +1098,14 @@ class API(object): list_id=None, owner_id=None, owner_screen_name=None): """ Perform bulk add of list members from user ID or screenname """ return self._add_list_members(list_to_csv(screen_name), - list_to_csv(user_id), - slug, list_id, owner_id, - owner_screen_name) + list_to_csv(user_id), slug, list_id, + owner_id, owner_screen_name) @property def _add_list_members(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all - :allowed_param:'screen_name', 'user_id', 'slug', 'list_id', - 'owner_id', 'owner_screen_name' - + :allowed_param: 'screen_name', 'user_id', 'slug', 'list_id', + 'owner_id', 'owner_screen_name' """ return bind_api( api=self, @@ -1058,19 +1118,18 @@ class API(object): ) def remove_list_members(self, screen_name=None, user_id=None, slug=None, - list_id=None, owner_id=None, owner_screen_name=None): + list_id=None, owner_id=None, + owner_screen_name=None): """ Perform bulk remove of list members from user ID or screenname """ return self._remove_list_members(list_to_csv(screen_name), - list_to_csv(user_id), - slug, list_id, owner_id, - owner_screen_name) + list_to_csv(user_id), slug, list_id, + owner_id, owner_screen_name) @property def _remove_list_members(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all - :allowed_param:'screen_name', 'user_id', 'slug', 'list_id', - 'owner_id', 'owner_screen_name' - + :allowed_param: 'screen_name', 'user_id', 'slug', 'list_id', + 'owner_id', 'owner_screen_name' """ return bind_api( api=self, @@ -1085,22 +1144,22 @@ class API(object): @property def list_members(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members - :allowed_param:'owner_screen_name', 'slug', 'list_id', - 'owner_id', 'cursor + :allowed_param: 'owner_screen_name', 'slug', 'list_id', 'owner_id', + 'cursor' """ return bind_api( api=self, path='/lists/members.json', payload_type='user', payload_list=True, - allowed_param=['owner_screen_name', 'slug', 'list_id', - 'owner_id', 'cursor'] + allowed_param=['owner_screen_name', 'slug', 'list_id', 'owner_id', + 'cursor'] ) @property def show_list_member(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members-show - :allowed_param:'list_id', 'slug', 'user_id', 'screen_name', - 'owner_screen_name', 'owner_id + :allowed_param: 'list_id', 'slug', 'user_id', 'screen_name', + 'owner_screen_name', 'owner_id' """ return bind_api( api=self, @@ -1113,54 +1172,50 @@ class API(object): @property def subscribe_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-create - :allowed_param:'owner_screen_name', 'slug', 'owner_id', - 'list_id' + :allowed_param: 'owner_screen_name', 'slug', 'owner_id', 'list_id' """ return bind_api( api=self, path='/lists/subscribers/create.json', method='POST', payload_type='list', - allowed_param=['owner_screen_name', 'slug', 'owner_id', - 'list_id'], + allowed_param=['owner_screen_name', 'slug', 'owner_id', 'list_id'], require_auth=True ) @property def unsubscribe_list(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-destroy - :allowed_param:'owner_screen_name', 'slug', 'owner_id', - 'list_id' + :allowed_param: 'owner_screen_name', 'slug', 'owner_id', 'list_id' """ return bind_api( api=self, path='/lists/subscribers/destroy.json', method='POST', payload_type='list', - allowed_param=['owner_screen_name', 'slug', 'owner_id', - 'list_id'], + allowed_param=['owner_screen_name', 'slug', 'owner_id', 'list_id'], require_auth=True ) @property def list_subscribers(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers - :allowed_param:'owner_screen_name', 'slug', 'owner_id', - 'list_id', 'cursor + :allowed_param: 'owner_screen_name', 'slug', 'owner_id', 'list_id', + 'cursor' """ return bind_api( api=self, path='/lists/subscribers.json', payload_type='user', payload_list=True, - allowed_param=['owner_screen_name', 'slug', 'owner_id', - 'list_id', 'cursor'] + allowed_param=['owner_screen_name', 'slug', 'owner_id', 'list_id', + 'cursor'] ) @property def show_list_subscriber(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers-show - :allowed_param:'owner_screen_name', 'slug', 'screen_name', - 'owner_id', 'list_id', 'user_id + :allowed_param: 'owner_screen_name', 'slug', 'screen_name', + 'owner_id', 'list_id', 'user_id' """ return bind_api( api=self, @@ -1182,7 +1237,7 @@ class API(object): @property def trends_place(self): """ :reference: https://developer.twitter.com/en/docs/trends/trends-for-location/api-reference/get-trends-place - :allowed_param:'id', 'exclude' + :allowed_param: 'id', 'exclude' """ return bind_api( api=self, @@ -1194,7 +1249,7 @@ class API(object): @property def trends_closest(self): """ :reference: https://developer.twitter.com/en/docs/trends/locations-with-trending-topics/api-reference/get-trends-closest - :allowed_param:'lat', 'long' + :allowed_param: 'lat', 'long' """ return bind_api( api=self, @@ -1206,9 +1261,9 @@ class API(object): @property def search(self): """ :reference: https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets - :allowed_param:'q', 'lang', 'locale', 'since_id', 'geocode', - 'max_id', 'until', 'result_type', 'count', - 'include_entities' + :allowed_param: 'q', 'lang', 'locale', 'since_id', 'geocode', + 'max_id', 'until', 'result_type', 'count', + 'include_entities' """ return bind_api( api=self, @@ -1222,7 +1277,8 @@ class API(object): @property def reverse_geocode(self): """ :reference: https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-reverse_geocode - :allowed_param:'lat', 'long', 'accuracy', 'granularity', 'max_results' + :allowed_param: 'lat', 'long', 'accuracy', 'granularity', + 'max_results' """ return bind_api( api=self, @@ -1235,7 +1291,7 @@ class API(object): @property def geo_id(self): """ :reference: https://developer.twitter.com/en/docs/geo/place-information/api-reference/get-geo-id-place_id - :allowed_param:'id' + :allowed_param: 'id' """ return bind_api( api=self, @@ -1247,8 +1303,8 @@ class API(object): @property def geo_search(self): """ :reference: https://developer.twitter.com/en/docs/geo/places-near-location/api-reference/get-geo-search - :allowed_param:'lat', 'long', 'query', 'ip', 'granularity', - 'accuracy', 'max_results', 'contained_within + :allowed_param: 'lat', 'long', 'query', 'ip', 'granularity', + 'accuracy', 'max_results', 'contained_within' """ return bind_api( @@ -1300,7 +1356,8 @@ class API(object): if f is None: try: if os.path.getsize(filename) > (max_size * 1024): - raise TweepError('File is too big, must be less than %skb.' % max_size) + raise TweepError('File is too big, must be less than %skb.' + % max_size) except os.error as e: raise TweepError('Unable to access file: %s' % e.strerror) @@ -1309,7 +1366,8 @@ class API(object): else: f.seek(0, 2) # Seek to end of file if f.tell() > (max_size * 1024): - raise TweepError('File is too big, must be less than %skb.' % max_size) + raise TweepError('File is too big, must be less than %skb.' + % max_size) f.seek(0) # Reset to beginning of file fp = f -- 2.25.1