Merge pull request #15 from erincongden/newfeatures

Muting, follow requests, local timeline, and more
This commit is contained in:
Lorenz Diener 2017-04-03 12:05:10 +02:00 cometido por GitHub
commit 1fc7c465b3
S'han modificat 2 arxius amb 138 adicions i 6 eliminacions

Veure arxiu

@ -99,6 +99,7 @@ User dicts
'header': URL for their header image 'header': URL for their header image
'id': Same as <numerical id> 'id': Same as <numerical id>
'username': The username (what you @ them with) 'username': The username (what you @ them with)
'locked': Denotes whether the account can be followed without a follow request
} }
Toot dicts Toot dicts
@ -108,7 +109,7 @@ Toot dicts
mastodon.toot("Hello from Python") mastodon.toot("Hello from Python")
# Returns the following dictionary: # 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 'created_at': Creation time
'mentions': A list of account dicts mentioned in the toot 'mentions': A list of account dicts mentioned in the toot
'uri': Descriptor for the toot 'uri': Descriptor for the toot
@ -123,6 +124,7 @@ Toot dicts
'reblog': Denotes whether the toot is a reblog 'reblog': Denotes whether the toot is a reblog
'url': URL of the toot 'url': URL of the toot
'content': Content of the toot, as HTML: '<p>Hello from Python</p>' 'content': Content of the toot, as HTML: '<p>Hello from Python</p>'
'spoiler_text': Warning text that should be displayed before the toot content
'favourited': Denotes whether the logged in user has favourited this toot 'favourited': Denotes whether the logged in user has favourited this toot
'account': Account dict for the logged in account 'account': Account dict for the logged in account
} }
@ -138,6 +140,8 @@ Relationship dicts
'following': Boolean denoting whether you follow them 'following': Boolean denoting whether you follow them
'id': Numerical id (same one as <numerical id>) 'id': Numerical id (same one as <numerical id>)
'blocking': Boolean denoting whether you are blocking them '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 Notification dicts
@ -205,6 +209,7 @@ user could see, as well as hashtag timelines and the public timeline.
.. automethod:: Mastodon.timeline .. automethod:: Mastodon.timeline
.. automethod:: Mastodon.timeline_home .. automethod:: Mastodon.timeline_home
.. automethod:: Mastodon.timeline_mentions .. automethod:: Mastodon.timeline_mentions
.. automethod:: Mastodon.timeline_local
.. automethod:: Mastodon.timeline_public .. automethod:: Mastodon.timeline_public
.. automethod:: Mastodon.timeline_hashtag .. automethod:: Mastodon.timeline_hashtag
@ -236,6 +241,28 @@ their relationships.
.. automethod:: Mastodon.account_relationships .. automethod:: Mastodon.account_relationships
.. automethod:: Mastodon.account_search .. 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
Reading data: Favourites
------------------------
This function allows you to get information about statuses favourited
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 Writing data: Statuses
---------------------- ----------------------
These functions allow you to post statuses to Mastodon and to These functions allow you to post statuses to Mastodon and to
@ -258,6 +285,15 @@ These functions allow you to interact with other accounts: To (un)follow and
.. automethod:: Mastodon.account_unfollow .. automethod:: Mastodon.account_unfollow
.. automethod:: Mastodon.account_block .. automethod:: Mastodon.account_block
.. automethod:: Mastodon.account_unblock .. automethod:: Mastodon.account_unblock
.. 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 Writing data: Media
------------------- -------------------

Veure arxiu

@ -166,14 +166,20 @@ class Mastodon:
## ##
def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): 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 Fetch statuses, most recent ones first. Timeline can be home, mentions, local,
or tag/hashtag. See the following functions documentation for what those do. public, or tag/hashtag. See the following functions documentation for what those do.
The default timeline is the "home" timeline. The default timeline is the "home" timeline.
Returns a list of toot dicts. 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) return self.__api_request('GET', '/api/v1/timelines/' + timeline, params)
def timeline_home(self, max_id = None, since_id = None, limit = None): def timeline_home(self, max_id = None, since_id = None, limit = None):
@ -192,6 +198,14 @@ class Mastodon:
""" """
return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit) 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): def timeline_public(self, max_id = None, since_id = None, limit = None):
""" """
Fetches the public / visible-network timeline. Fetches the public / visible-network timeline.
@ -319,10 +333,52 @@ class Mastodon:
params = self.__generate_params(locals()) params = self.__generate_params(locals())
return self.__api_request('GET', '/api/v1/accounts/search', params) 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')
###
# 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')
###
# 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 # 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 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 up to four pieces of media (Uploaded via media_post()). media_ids can
@ -342,6 +398,10 @@ class Mastodon:
If not passed in, visibility defaults to match the current account's If not passed in, visibility defaults to match the current account's
privacy setting (private if the account is locked, public otherwise). 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. Returns a toot dict with the new status.
""" """
params_initial = locals() params_initial = locals()
@ -409,7 +469,8 @@ class Mastodon:
return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite") return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite")
def status_unfavourite(self, id): def status_unfavourite(self, id):
"""Favourite a status. """
Un-favourite a status.
Returns a toot dict with the un-favourited status. Returns a toot dict with the un-favourited status.
""" """
@ -450,6 +511,41 @@ class Mastodon:
""" """
return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock") 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: 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 # Writing data: Media
### ###