From f734a45fb667baf40d2cae3696934f91f1d5d8d0 Mon Sep 17 00:00:00 2001 From: Erin Congden Date: Sun, 2 Apr 2017 18:46:43 -0700 Subject: [PATCH 1/5] Added spoiler text support --- docs/index.rst | 3 ++- mastodon/Mastodon.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 121dc83..39af190 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -108,7 +108,7 @@ Toot dicts mastodon.toot("Hello from Python") # Returns the following dictionary: { - 'sensitive': Denotes whether the toot is marked sensitive + 'sensitive': Denotes whether media attachments to the toot are marked sensitive 'created_at': Creation time 'mentions': A list of account dicts mentioned in the toot 'uri': Descriptor for the toot @@ -123,6 +123,7 @@ Toot dicts 'reblog': Denotes whether the toot is a reblog 'url': URL of the toot 'content': Content of the toot, as HTML: '

Hello from Python

' + 'spoiler_text': Warning text that should be displayed before the toot content 'favourited': Denotes whether the logged in user has favourited this toot 'account': Account dict for the logged in account } diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index b9ab05b..1d0e69f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -318,7 +318,7 @@ class Mastodon: ### # Writing data: Statuses ### - def status_post(self, status, in_reply_to_id = None, media_ids = None, sensitive = False, visibility = ''): + def status_post(self, status, in_reply_to_id = None, media_ids = None, sensitive = False, visibility = '', spoiler_text = None): """ Post a status. Can optionally be in reply to another status and contain up to four pieces of media (Uploaded via media_post()). media_ids can @@ -338,6 +338,10 @@ class Mastodon: If not passed in, visibility defaults to match the current account's privacy setting (private if the account is locked, public otherwise). + The spoiler_text parameter is a string to be shown as a warning before + the text of the status. If no text is passed in, no warning will be + displayed. + Returns a toot dict with the new status. """ params_initial = locals() From 9eaf955bfc8bda2a2e114721347f9b2ccf06b055 Mon Sep 17 00:00:00 2001 From: Erin Congden Date: Sun, 2 Apr 2017 10:35:42 -0700 Subject: [PATCH 2/5] Added local timeline support --- docs/index.rst | 1 + mastodon/Mastodon.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 39af190..90e8478 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -206,6 +206,7 @@ user could see, as well as hashtag timelines and the public timeline. .. automethod:: Mastodon.timeline .. automethod:: Mastodon.timeline_home .. automethod:: Mastodon.timeline_mentions +.. automethod:: Mastodon.timeline_local .. automethod:: Mastodon.timeline_public .. automethod:: Mastodon.timeline_hashtag diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 1d0e69f..641c415 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -162,14 +162,20 @@ class Mastodon: ## def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): """ - Fetch statuses, most recent ones first. Timeline can be home, mentions, public - or tag/hashtag. See the following functions documentation for what those do. + Fetch statuses, most recent ones first. Timeline can be home, mentions, local, + public, or tag/hashtag. See the following functions documentation for what those do. The default timeline is the "home" timeline. Returns a list of toot dicts. """ - params = self.__generate_params(locals(), ['timeline']) + params_initial = locals() + + if timeline == "local": + timeline = "public" + params_initial['local'] = True + + params = self.__generate_params(params_initial, ['timeline']) return self.__api_request('GET', '/api/v1/timelines/' + timeline, params) def timeline_home(self, max_id = None, since_id = None, limit = None): @@ -188,6 +194,14 @@ class Mastodon: """ return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit) + def timeline_local(self, max_id = None, since_id = None, limit = None): + """ + Fetches the local / instance-wide timeline. + + Returns a list of toot dicts. + """ + return self.timeline('local', max_id = max_id, since_id = since_id, limit = limit) + def timeline_public(self, max_id = None, since_id = None, limit = None): """ Fetches the public / visible-network timeline. From 36781699c135b3a4cd89973ef2f5079f123a0567 Mon Sep 17 00:00:00 2001 From: Erin Congden Date: Sun, 2 Apr 2017 20:20:38 -0700 Subject: [PATCH 3/5] Add (un)muting accounts and reading mutes/blocks --- docs/index.rst | 11 +++++++++++ mastodon/Mastodon.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 90e8478..f9915e6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -139,6 +139,7 @@ Relationship dicts 'following': Boolean denoting whether you follow them 'id': Numerical id (same one as ) 'blocking': Boolean denoting whether you are blocking them + 'muting': Boolean denoting whether you are muting them } Notification dicts @@ -238,6 +239,14 @@ their relationships. .. automethod:: Mastodon.account_relationships .. automethod:: Mastodon.account_search +Reading data: Mutes and blocks +------------------------------ +These functions allow you to get information about accounts that are +muted or blocked by the logged in user. + +.. automethod:: Mastodon.mutes +.. automethod:: Mastodon.blocks + Writing data: Statuses ---------------------- These functions allow you to post statuses to Mastodon and to @@ -260,6 +269,8 @@ These functions allow you to interact with other accounts: To (un)follow and .. automethod:: Mastodon.account_unfollow .. automethod:: Mastodon.account_block .. automethod:: Mastodon.account_unblock +.. automethod:: Mastodon.account_mute +.. automethod:: Mastodon.account_unmute Writing data: Media ------------------- diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 641c415..1c9ca4b 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -329,6 +329,25 @@ class Mastodon: params = self.__generate_params(locals()) return self.__api_request('GET', '/api/v1/accounts/search', params) + ### + # Reading data: Mutes and Blocks + ### + def mutes(self): + """ + Fetch a list of users muted by the authenticated user. + + Returns a list of user dicts. + """ + return self.__api_request('GET', '/api/v1/mutes') + + def blocks(self): + """ + Fetch a list of users blocked by the authenticated user. + + Returns a list of user dicts. + """ + return self.__api_request('GET', '/api/v1/blocks') + ### # Writing data: Statuses ### @@ -462,6 +481,22 @@ class Mastodon: """ return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock") + def account_mute(self, id): + """ + Mute a user. + + Returns a relationship dict containing the updated relationship to the user. + """ + return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/mute") + + def account_unmute(self, id): + """ + Unmute a user. + + Returns a relationship dict containing the updated relationship to the user. + """ + return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unmute") + ### # Writing data: Media ### From 38ebcda76bc0c264f8384f55c5b32bf049b2d6be Mon Sep 17 00:00:00 2001 From: Erin Congden Date: Sun, 2 Apr 2017 20:48:10 -0700 Subject: [PATCH 4/5] Added getting a list of favourited toots --- docs/index.rst | 7 +++++++ mastodon/Mastodon.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index f9915e6..9dc37e5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -247,6 +247,13 @@ muted or blocked by the logged in user. .. automethod:: Mastodon.mutes .. automethod:: Mastodon.blocks +Reading data: Favourites +------------------------ +This function allows you to get information about statuses favourited +by the authenticated user. + +.. authomethod:: Mastodon.favourites + Writing data: Statuses ---------------------- These functions allow you to post statuses to Mastodon and to diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 1c9ca4b..d42c13f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -348,6 +348,17 @@ class Mastodon: """ return self.__api_request('GET', '/api/v1/blocks') + ### + # Reading data: Favourites + ### + def favourites(self): + """ + Fetch the authenticated user's favourited statuses. + + Returns a list of toot dicts. + """ + return self.__api_request('GET', '/api/v1/favourites') + ### # Writing data: Statuses ### @@ -440,7 +451,8 @@ class Mastodon: return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite") def status_unfavourite(self, id): - """Favourite a status. + """ + Un-favourite a status. Returns a toot dict with the un-favourited status. """ From ca0b6c115bcb8f6b79b22f5ccd648a2d6b7d7fc5 Mon Sep 17 00:00:00 2001 From: Erin Congden Date: Sun, 2 Apr 2017 20:53:32 -0700 Subject: [PATCH 5/5] Added follow requests support --- docs/index.rst | 16 ++++++++++++++++ mastodon/Mastodon.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 9dc37e5..8be642a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -99,6 +99,7 @@ User dicts 'header': URL for their header image 'id': Same as 'username': The username (what you @ them with) + 'locked': Denotes whether the account can be followed without a follow request } Toot dicts @@ -140,6 +141,7 @@ Relationship dicts 'id': Numerical id (same one as ) 'blocking': Boolean denoting whether you are blocking them 'muting': Boolean denoting whether you are muting them + 'requested': Boolean denoting whether you have sent them a follow request } Notification dicts @@ -254,6 +256,13 @@ by the authenticated user. .. authomethod:: Mastodon.favourites +Reading data: Follow requests +----------------------------- +This function allows you to get a list of pending incoming follow +requests for the authenticated user. + +.. automethod:: Mastodon.follow_requests + Writing data: Statuses ---------------------- These functions allow you to post statuses to Mastodon and to @@ -279,6 +288,13 @@ These functions allow you to interact with other accounts: To (un)follow and .. automethod:: Mastodon.account_mute .. automethod:: Mastodon.account_unmute +Writing data: Follow requests +----------------------------- +These functions allow you to accept or reject incoming follow requests. + +.. automethod:: Mastodon.follow_request_authorize +.. automethod:: Mastodon.follow_request_reject + Writing data: Media ------------------- This function allows you to upload media to Mastodon. The returned diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index d42c13f..06fe8a1 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -359,6 +359,18 @@ class Mastodon: """ return self.__api_request('GET', '/api/v1/favourites') + ### + # Reading data: Follow requests + ### + def follow_requests(self, max_id = None, since_id = None, limit = None): + """ + Fetch the authenticated user's incoming follow requests. + + Returns a list of user dicts. + """ + params = self.__generate_params(locals()) + return self.__api_request('GET', '/api/v1/follow_requests', params) + ### # Writing data: Statuses ### @@ -509,6 +521,25 @@ class Mastodon: """ return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unmute") + ### + # Writing data: Follow requests + ### + def follow_request_authorize(self, id): + """ + Accept an incoming follow request. + + Returns a user dict of the authorized account. + """ + return self.__api_request('POST', '/api/v1/follow_requests/' + str(id) + "/authorize") + + def follow_request_reject(self, id): + """ + Reject an incoming follow request. + + Returns a user dict of the rejected account. + """ + return self.__api_request('POST', '/api/v1/follow_requests/' + str(id) + "/reject") + ### # Writing data: Media ###