aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-04-03 12:05:10 +0200
committerGitHub <[email protected]>2017-04-03 12:05:10 +0200
commit1fc7c465b33821592e80a592d615e133f048774a (patch)
tree57f8fc8dda1267fd4fb86f0b7b7af20e22112a13
parentcd1beedffe15665324f02a11732454e3deaadf6a (diff)
parentca0b6c115bcb8f6b79b22f5ccd648a2d6b7d7fc5 (diff)
downloadmastodon.py-1fc7c465b33821592e80a592d615e133f048774a.tar.gz
Merge pull request #15 from erincongden/newfeatures
Muting, follow requests, local timeline, and more
-rw-r--r--docs/index.rst38
-rw-r--r--mastodon/Mastodon.py106
2 files changed, 138 insertions, 6 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 3871972..6279d48 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -99,6 +99,7 @@ User dicts
99 'header': URL for their header image 99 'header': URL for their header image
100 'id': Same as <numerical id> 100 'id': Same as <numerical id>
101 'username': The username (what you @ them with) 101 'username': The username (what you @ them with)
102 'locked': Denotes whether the account can be followed without a follow request
102 } 103 }
103 104
104Toot dicts 105Toot dicts
@@ -108,7 +109,7 @@ Toot dicts
108 mastodon.toot("Hello from Python") 109 mastodon.toot("Hello from Python")
109 # Returns the following dictionary: 110 # Returns the following dictionary:
110 { 111 {
111 'sensitive': Denotes whether the toot is marked sensitive 112 'sensitive': Denotes whether media attachments to the toot are marked sensitive
112 'created_at': Creation time 113 'created_at': Creation time
113 'mentions': A list of account dicts mentioned in the toot 114 'mentions': A list of account dicts mentioned in the toot
114 'uri': Descriptor for the toot 115 'uri': Descriptor for the toot
@@ -123,6 +124,7 @@ Toot dicts
123 'reblog': Denotes whether the toot is a reblog 124 'reblog': Denotes whether the toot is a reblog
124 'url': URL of the toot 125 'url': URL of the toot
125 'content': Content of the toot, as HTML: '<p>Hello from Python</p>' 126 'content': Content of the toot, as HTML: '<p>Hello from Python</p>'
127 'spoiler_text': Warning text that should be displayed before the toot content
126 'favourited': Denotes whether the logged in user has favourited this toot 128 'favourited': Denotes whether the logged in user has favourited this toot
127 'account': Account dict for the logged in account 129 'account': Account dict for the logged in account
128 } 130 }
@@ -138,6 +140,8 @@ Relationship dicts
138 'following': Boolean denoting whether you follow them 140 'following': Boolean denoting whether you follow them
139 'id': Numerical id (same one as <numerical id>) 141 'id': Numerical id (same one as <numerical id>)
140 'blocking': Boolean denoting whether you are blocking them 142 'blocking': Boolean denoting whether you are blocking them
143 'muting': Boolean denoting whether you are muting them
144 'requested': Boolean denoting whether you have sent them a follow request
141 } 145 }
142 146
143Notification dicts 147Notification dicts
@@ -205,6 +209,7 @@ user could see, as well as hashtag timelines and the public timeline.
205.. automethod:: Mastodon.timeline 209.. automethod:: Mastodon.timeline
206.. automethod:: Mastodon.timeline_home 210.. automethod:: Mastodon.timeline_home
207.. automethod:: Mastodon.timeline_mentions 211.. automethod:: Mastodon.timeline_mentions
212.. automethod:: Mastodon.timeline_local
208.. automethod:: Mastodon.timeline_public 213.. automethod:: Mastodon.timeline_public
209.. automethod:: Mastodon.timeline_hashtag 214.. automethod:: Mastodon.timeline_hashtag
210 215
@@ -236,6 +241,28 @@ their relationships.
236.. automethod:: Mastodon.account_relationships 241.. automethod:: Mastodon.account_relationships
237.. automethod:: Mastodon.account_search 242.. automethod:: Mastodon.account_search
238 243
244Reading data: Mutes and blocks
245------------------------------
246These functions allow you to get information about accounts that are
247muted or blocked by the logged in user.
248
249.. automethod:: Mastodon.mutes
250.. automethod:: Mastodon.blocks
251
252Reading data: Favourites
253------------------------
254This function allows you to get information about statuses favourited
255by the authenticated user.
256
257.. authomethod:: Mastodon.favourites
258
259Reading data: Follow requests
260-----------------------------
261This function allows you to get a list of pending incoming follow
262requests for the authenticated user.
263
264.. automethod:: Mastodon.follow_requests
265
239Writing data: Statuses 266Writing data: Statuses
240---------------------- 267----------------------
241These functions allow you to post statuses to Mastodon and to 268These 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
258.. automethod:: Mastodon.account_unfollow 285.. automethod:: Mastodon.account_unfollow
259.. automethod:: Mastodon.account_block 286.. automethod:: Mastodon.account_block
260.. automethod:: Mastodon.account_unblock 287.. automethod:: Mastodon.account_unblock
288.. automethod:: Mastodon.account_mute
289.. automethod:: Mastodon.account_unmute
290
291Writing data: Follow requests
292-----------------------------
293These functions allow you to accept or reject incoming follow requests.
294
295.. automethod:: Mastodon.follow_request_authorize
296.. automethod:: Mastodon.follow_request_reject
261 297
262Writing data: Media 298Writing data: Media
263------------------- 299-------------------
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index a5cf428..69d71ec 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -166,14 +166,20 @@ class Mastodon:
166 ## 166 ##
167 def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): 167 def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None):
168 """ 168 """
169 Fetch statuses, most recent ones first. Timeline can be home, mentions, public 169 Fetch statuses, most recent ones first. Timeline can be home, mentions, local,
170 or tag/hashtag. See the following functions documentation for what those do. 170 public, or tag/hashtag. See the following functions documentation for what those do.
171 171
172 The default timeline is the "home" timeline. 172 The default timeline is the "home" timeline.
173 173
174 Returns a list of toot dicts. 174 Returns a list of toot dicts.
175 """ 175 """
176 params = self.__generate_params(locals(), ['timeline']) 176 params_initial = locals()
177
178 if timeline == "local":
179 timeline = "public"
180 params_initial['local'] = True
181
182 params = self.__generate_params(params_initial, ['timeline'])
177 return self.__api_request('GET', '/api/v1/timelines/' + timeline, params) 183 return self.__api_request('GET', '/api/v1/timelines/' + timeline, params)
178 184
179 def timeline_home(self, max_id = None, since_id = None, limit = None): 185 def timeline_home(self, max_id = None, since_id = None, limit = None):
@@ -192,6 +198,14 @@ class Mastodon:
192 """ 198 """
193 return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit) 199 return self.timeline('mentions', max_id = max_id, since_id = since_id, limit = limit)
194 200
201 def timeline_local(self, max_id = None, since_id = None, limit = None):
202 """
203 Fetches the local / instance-wide timeline.
204
205 Returns a list of toot dicts.
206 """
207 return self.timeline('local', max_id = max_id, since_id = since_id, limit = limit)
208
195 def timeline_public(self, max_id = None, since_id = None, limit = None): 209 def timeline_public(self, max_id = None, since_id = None, limit = None):
196 """ 210 """
197 Fetches the public / visible-network timeline. 211 Fetches the public / visible-network timeline.
@@ -320,9 +334,51 @@ class Mastodon:
320 return self.__api_request('GET', '/api/v1/accounts/search', params) 334 return self.__api_request('GET', '/api/v1/accounts/search', params)
321 335
322 ### 336 ###
337 # Reading data: Mutes and Blocks
338 ###
339 def mutes(self):
340 """
341 Fetch a list of users muted by the authenticated user.
342
343 Returns a list of user dicts.
344 """
345 return self.__api_request('GET', '/api/v1/mutes')
346
347 def blocks(self):
348 """
349 Fetch a list of users blocked by the authenticated user.
350
351 Returns a list of user dicts.
352 """
353 return self.__api_request('GET', '/api/v1/blocks')
354
355 ###
356 # Reading data: Favourites
357 ###
358 def favourites(self):
359 """
360 Fetch the authenticated user's favourited statuses.
361
362 Returns a list of toot dicts.
363 """
364 return self.__api_request('GET', '/api/v1/favourites')
365
366 ###
367 # Reading data: Follow requests
368 ###
369 def follow_requests(self, max_id = None, since_id = None, limit = None):
370 """
371 Fetch the authenticated user's incoming follow requests.
372
373 Returns a list of user dicts.
374 """
375 params = self.__generate_params(locals())
376 return self.__api_request('GET', '/api/v1/follow_requests', params)
377
378 ###
323 # Writing data: Statuses 379 # Writing data: Statuses
324 ### 380 ###
325 def status_post(self, status, in_reply_to_id = None, media_ids = None, sensitive = False, visibility = ''): 381 def status_post(self, status, in_reply_to_id = None, media_ids = None, sensitive = False, visibility = '', spoiler_text = None):
326 """ 382 """
327 Post a status. Can optionally be in reply to another status and contain 383 Post a status. Can optionally be in reply to another status and contain
328 up to four pieces of media (Uploaded via media_post()). media_ids can 384 up to four pieces of media (Uploaded via media_post()). media_ids can
@@ -342,6 +398,10 @@ class Mastodon:
342 If not passed in, visibility defaults to match the current account's 398 If not passed in, visibility defaults to match the current account's
343 privacy setting (private if the account is locked, public otherwise). 399 privacy setting (private if the account is locked, public otherwise).
344 400
401 The spoiler_text parameter is a string to be shown as a warning before
402 the text of the status. If no text is passed in, no warning will be
403 displayed.
404
345 Returns a toot dict with the new status. 405 Returns a toot dict with the new status.
346 """ 406 """
347 params_initial = locals() 407 params_initial = locals()
@@ -409,7 +469,8 @@ class Mastodon:
409 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite") 469 return self.__api_request('POST', '/api/v1/statuses/' + str(id) + "/favourite")
410 470
411 def status_unfavourite(self, id): 471 def status_unfavourite(self, id):
412 """Favourite a status. 472 """
473 Un-favourite a status.
413 474
414 Returns a toot dict with the un-favourited status. 475 Returns a toot dict with the un-favourited status.
415 """ 476 """
@@ -450,6 +511,41 @@ class Mastodon:
450 """ 511 """
451 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock") 512 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unblock")
452 513
514 def account_mute(self, id):
515 """
516 Mute a user.
517
518 Returns a relationship dict containing the updated relationship to the user.
519 """
520 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/mute")
521
522 def account_unmute(self, id):
523 """
524 Unmute a user.
525
526 Returns a relationship dict containing the updated relationship to the user.
527 """
528 return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unmute")
529
530 ###
531 # Writing data: Follow requests
532 ###
533 def follow_request_authorize(self, id):
534 """
535 Accept an incoming follow request.
536
537 Returns a user dict of the authorized account.
538 """
539 return self.__api_request('POST', '/api/v1/follow_requests/' + str(id) + "/authorize")
540
541 def follow_request_reject(self, id):
542 """
543 Reject an incoming follow request.
544
545 Returns a user dict of the rejected account.
546 """
547 return self.__api_request('POST', '/api/v1/follow_requests/' + str(id) + "/reject")
548
453 ### 549 ###
454 # Writing data: Media 550 # Writing data: Media
455 ### 551 ###
Powered by cgit v1.2.3 (git 2.41.0)