diff options
Diffstat (limited to 'mastodon/statuses.py')
-rw-r--r-- | mastodon/statuses.py | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/mastodon/statuses.py b/mastodon/statuses.py index 36a7d2b..eb372d8 100644 --- a/mastodon/statuses.py +++ b/mastodon/statuses.py | |||
@@ -23,8 +23,7 @@ class Mastodon(Internals): | |||
23 | Returns a :ref:`status dict <status dict>`. | 23 | Returns a :ref:`status dict <status dict>`. |
24 | """ | 24 | """ |
25 | id = self.__unpack_id(id) | 25 | id = self.__unpack_id(id) |
26 | url = '/api/v1/statuses/{0}'.format(str(id)) | 26 | return self.__api_request('GET', f'/api/v1/statuses/{id}') |
27 | return self.__api_request('GET', url) | ||
28 | 27 | ||
29 | @api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD) | 28 | @api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD) |
30 | def status_card(self, id): | 29 | def status_card(self, id): |
@@ -45,8 +44,7 @@ class Mastodon(Internals): | |||
45 | return self.status(id).card | 44 | return self.status(id).card |
46 | else: | 45 | else: |
47 | id = self.__unpack_id(id) | 46 | id = self.__unpack_id(id) |
48 | url = '/api/v1/statuses/{0}/card'.format(str(id)) | 47 | return self.__api_request('GET', f'/api/v1/statuses/{id}/card') |
49 | return self.__api_request('GET', url) | ||
50 | 48 | ||
51 | @api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT) | 49 | @api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT) |
52 | def status_context(self, id): | 50 | def status_context(self, id): |
@@ -58,8 +56,7 @@ class Mastodon(Internals): | |||
58 | Returns a :ref:`context dict <context dict>`. | 56 | Returns a :ref:`context dict <context dict>`. |
59 | """ | 57 | """ |
60 | id = self.__unpack_id(id) | 58 | id = self.__unpack_id(id) |
61 | url = '/api/v1/statuses/{0}/context'.format(str(id)) | 59 | return self.__api_request('GET', f'/api/v1/statuses/{id}/context') |
62 | return self.__api_request('GET', url) | ||
63 | 60 | ||
64 | @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) | 61 | @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) |
65 | def status_reblogged_by(self, id): | 62 | def status_reblogged_by(self, id): |
@@ -71,8 +68,7 @@ class Mastodon(Internals): | |||
71 | Returns a list of :ref:`account dicts <account dicts>`. | 68 | Returns a list of :ref:`account dicts <account dicts>`. |
72 | """ | 69 | """ |
73 | id = self.__unpack_id(id) | 70 | id = self.__unpack_id(id) |
74 | url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id)) | 71 | return self.__api_request('GET', f'/api/v1/statuses/{id}/reblogged_by') |
75 | return self.__api_request('GET', url) | ||
76 | 72 | ||
77 | @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) | 73 | @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) |
78 | def status_favourited_by(self, id): | 74 | def status_favourited_by(self, id): |
@@ -84,8 +80,7 @@ class Mastodon(Internals): | |||
84 | Returns a list of :ref:`account dicts <account dicts>`. | 80 | Returns a list of :ref:`account dicts <account dicts>`. |
85 | """ | 81 | """ |
86 | id = self.__unpack_id(id) | 82 | id = self.__unpack_id(id) |
87 | url = '/api/v1/statuses/{0}/favourited_by'.format(str(id)) | 83 | return self.__api_request('GET', f'/api/v1/statuses/{id}/favourited_by') |
88 | return self.__api_request('GET', url) | ||
89 | 84 | ||
90 | ### | 85 | ### |
91 | # Reading data: Scheduled statuses | 86 | # Reading data: Scheduled statuses |
@@ -107,9 +102,8 @@ class Mastodon(Internals): | |||
107 | Returns a :ref:`scheduled status dict <scheduled status dict>`. | 102 | Returns a :ref:`scheduled status dict <scheduled status dict>`. |
108 | """ | 103 | """ |
109 | id = self.__unpack_id(id) | 104 | id = self.__unpack_id(id) |
110 | url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) | 105 | return self.__api_request('GET', f'/api/v1/scheduled_statuses/{id}') |
111 | return self.__api_request('GET', url) | 106 | |
112 | |||
113 | ### | 107 | ### |
114 | # Writing data: Statuses | 108 | # Writing data: Statuses |
115 | ### | 109 | ### |
@@ -150,7 +144,7 @@ class Mastodon(Internals): | |||
150 | else: | 144 | else: |
151 | params_initial['visibility'] = params_initial['visibility'].lower() | 145 | params_initial['visibility'] = params_initial['visibility'].lower() |
152 | if params_initial['visibility'] not in valid_visibilities: | 146 | if params_initial['visibility'] not in valid_visibilities: |
153 | raise ValueError('Invalid visibility value! Acceptable values are %s' % valid_visibilities) | 147 | raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}') |
154 | 148 | ||
155 | if params_initial['language'] is None: | 149 | if params_initial['language'] is None: |
156 | del params_initial['language'] | 150 | del params_initial['language'] |
@@ -170,7 +164,7 @@ class Mastodon(Internals): | |||
170 | for media_id in media_ids: | 164 | for media_id in media_ids: |
171 | media_ids_proper.append(self.__unpack_id(media_id)) | 165 | media_ids_proper.append(self.__unpack_id(media_id)) |
172 | except Exception as e: | 166 | except Exception as e: |
173 | raise MastodonIllegalArgumentError("Invalid media dict: %s" % e) | 167 | raise MastodonIllegalArgumentError(f"Invalid media dict: {e}") |
174 | 168 | ||
175 | params_initial["media_ids"] = media_ids_proper | 169 | params_initial["media_ids"] = media_ids_proper |
176 | 170 | ||
@@ -187,7 +181,7 @@ class Mastodon(Internals): | |||
187 | return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json) | 181 | return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json) |
188 | else: | 182 | else: |
189 | # Edit | 183 | # Edit |
190 | return self.__api_request('PUT', '/api/v1/statuses/{0}'.format(str(self.__unpack_id(edit))), params, headers=headers, use_json=use_json) | 184 | return self.__api_request('PUT', f'/api/v1/statuses/{self.__unpack_id(edit)}', params, headers=headers, use_json=use_json) |
191 | 185 | ||
192 | @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) | 186 | @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) |
193 | def status_post(self, status, in_reply_to_id=None, media_ids=None, | 187 | def status_post(self, status, in_reply_to_id=None, media_ids=None, |
@@ -303,7 +297,7 @@ class Mastodon(Internals): | |||
303 | will have three, and so on. | 297 | will have three, and so on. |
304 | """ | 298 | """ |
305 | id = self.__unpack_id(id) | 299 | id = self.__unpack_id(id) |
306 | return self.__api_request('GET', "/api/v1/statuses/{0}/history".format(str(id))) | 300 | return self.__api_request('GET', f"/api/v1/statuses/{id}/history") |
307 | 301 | ||
308 | def status_source(self, id): | 302 | def status_source(self, id): |
309 | """ | 303 | """ |
@@ -314,7 +308,7 @@ class Mastodon(Internals): | |||
314 | instead. | 308 | instead. |
315 | """ | 309 | """ |
316 | id = self.__unpack_id(id) | 310 | id = self.__unpack_id(id) |
317 | return self.__api_request('GET', "/api/v1/statuses/{0}/source".format(str(id))) | 311 | return self.__api_request('GET', f"/api/v1/statuses/{id}/source") |
318 | 312 | ||
319 | @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) | 313 | @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) |
320 | def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None, | 314 | def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None, |
@@ -372,8 +366,7 @@ class Mastodon(Internals): | |||
372 | "delete and redraft" functionality) | 366 | "delete and redraft" functionality) |
373 | """ | 367 | """ |
374 | id = self.__unpack_id(id) | 368 | id = self.__unpack_id(id) |
375 | url = '/api/v1/statuses/{0}'.format(str(id)) | 369 | return self.__api_request('DELETE', f'/api/v1/statuses/{id}') |
376 | return self.__api_request('DELETE', url) | ||
377 | 370 | ||
378 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) | 371 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) |
379 | def status_reblog(self, id, visibility=None): | 372 | def status_reblog(self, id, visibility=None): |
@@ -390,12 +383,10 @@ class Mastodon(Internals): | |||
390 | if 'visibility' in params: | 383 | if 'visibility' in params: |
391 | params['visibility'] = params['visibility'].lower() | 384 | params['visibility'] = params['visibility'].lower() |
392 | if params['visibility'] not in valid_visibilities: | 385 | if params['visibility'] not in valid_visibilities: |
393 | raise ValueError('Invalid visibility value! Acceptable ' | 386 | raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}') |
394 | 'values are %s' % valid_visibilities) | ||
395 | 387 | ||
396 | id = self.__unpack_id(id) | 388 | id = self.__unpack_id(id) |
397 | url = '/api/v1/statuses/{0}/reblog'.format(str(id)) | 389 | return self.__api_request('POST', f'/api/v1/statuses/{id}/reblog', params) |
398 | return self.__api_request('POST', url, params) | ||
399 | 390 | ||
400 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) | 391 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) |
401 | def status_unreblog(self, id): | 392 | def status_unreblog(self, id): |
@@ -405,8 +396,7 @@ class Mastodon(Internals): | |||
405 | Returns a :ref:`status dict <status dict>` with the status that used to be reblogged. | 396 | Returns a :ref:`status dict <status dict>` with the status that used to be reblogged. |
406 | """ | 397 | """ |
407 | id = self.__unpack_id(id) | 398 | id = self.__unpack_id(id) |
408 | url = '/api/v1/statuses/{0}/unreblog'.format(str(id)) | 399 | return self.__api_request('POST', f'/api/v1/statuses/{id}/unreblog') |
409 | return self.__api_request('POST', url) | ||
410 | 400 | ||
411 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) | 401 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) |
412 | def status_favourite(self, id): | 402 | def status_favourite(self, id): |
@@ -416,8 +406,7 @@ class Mastodon(Internals): | |||
416 | Returns a :ref:`status dict <status dict>` with the favourited status. | 406 | Returns a :ref:`status dict <status dict>` with the favourited status. |
417 | """ | 407 | """ |
418 | id = self.__unpack_id(id) | 408 | id = self.__unpack_id(id) |
419 | url = '/api/v1/statuses/{0}/favourite'.format(str(id)) | 409 | return self.__api_request('POST', f'/api/v1/statuses/{id}/favourite') |
420 | return self.__api_request('POST', url) | ||
421 | 410 | ||
422 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) | 411 | @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) |
423 | def status_unfavourite(self, id): | 412 | def status_unfavourite(self, id): |
@@ -427,8 +416,7 @@ class Mastodon(Internals): | |||
427 | Returns a :ref:`status dict <status dict>` with the un-favourited status. | 416 | Returns a :ref:`status dict <status dict>` with the un-favourited status. |
428 | """ | 417 | """ |
429 | id = self.__unpack_id(id) | 418 | id = self.__unpack_id(id) |
430 | url = '/api/v1/statuses/{0}/unfavourite'.format(str(id)) | 419 | return self.__api_request('POST', f'/api/v1/statuses/{id}/unfavourite') |
431 | return self.__api_request('POST', url) | ||
432 | 420 | ||
433 | @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) | 421 | @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) |
434 | def status_mute(self, id): | 422 | def status_mute(self, id): |
@@ -438,8 +426,7 @@ class Mastodon(Internals): | |||
438 | Returns a :ref:`status dict <status dict>` with the now muted status | 426 | Returns a :ref:`status dict <status dict>` with the now muted status |
439 | """ | 427 | """ |
440 | id = self.__unpack_id(id) | 428 | id = self.__unpack_id(id) |
441 | url = '/api/v1/statuses/{0}/mute'.format(str(id)) | 429 | return self.__api_request('POST', f'/api/v1/statuses/{id}/mute') |
442 | return self.__api_request('POST', url) | ||
443 | 430 | ||
444 | @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) | 431 | @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) |
445 | def status_unmute(self, id): | 432 | def status_unmute(self, id): |
@@ -449,8 +436,7 @@ class Mastodon(Internals): | |||
449 | Returns a :ref:`status dict <status dict>` with the status that used to be muted. | 436 | Returns a :ref:`status dict <status dict>` with the status that used to be muted. |
450 | """ | 437 | """ |
451 | id = self.__unpack_id(id) | 438 | id = self.__unpack_id(id) |
452 | url = '/api/v1/statuses/{0}/unmute'.format(str(id)) | 439 | return self.__api_request('POST', f'/api/v1/statuses/{id}/unmute') |
453 | return self.__api_request('POST', url) | ||
454 | 440 | ||
455 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) | 441 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) |
456 | def status_pin(self, id): | 442 | def status_pin(self, id): |
@@ -460,8 +446,7 @@ class Mastodon(Internals): | |||
460 | Returns a :ref:`status dict <status dict>` with the now pinned status | 446 | Returns a :ref:`status dict <status dict>` with the now pinned status |
461 | """ | 447 | """ |
462 | id = self.__unpack_id(id) | 448 | id = self.__unpack_id(id) |
463 | url = '/api/v1/statuses/{0}/pin'.format(str(id)) | 449 | return self.__api_request('POST', f'/api/v1/statuses/{id}/pin') |
464 | return self.__api_request('POST', url) | ||
465 | 450 | ||
466 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) | 451 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) |
467 | def status_unpin(self, id): | 452 | def status_unpin(self, id): |
@@ -471,8 +456,7 @@ class Mastodon(Internals): | |||
471 | Returns a :ref:`status dict <status dict>` with the status that used to be pinned. | 456 | Returns a :ref:`status dict <status dict>` with the status that used to be pinned. |
472 | """ | 457 | """ |
473 | id = self.__unpack_id(id) | 458 | id = self.__unpack_id(id) |
474 | url = '/api/v1/statuses/{0}/unpin'.format(str(id)) | 459 | return self.__api_request('POST', f'/api/v1/statuses/{id}/unpin') |
475 | return self.__api_request('POST', url) | ||
476 | 460 | ||
477 | @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) | 461 | @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) |
478 | def status_bookmark(self, id): | 462 | def status_bookmark(self, id): |
@@ -482,8 +466,7 @@ class Mastodon(Internals): | |||
482 | Returns a :ref:`status dict <status dict>` with the now bookmarked status | 466 | Returns a :ref:`status dict <status dict>` with the now bookmarked status |
483 | """ | 467 | """ |
484 | id = self.__unpack_id(id) | 468 | id = self.__unpack_id(id) |
485 | url = '/api/v1/statuses/{0}/bookmark'.format(str(id)) | 469 | return self.__api_request('POST', f'/api/v1/statuses/{id}/bookmark') |
486 | return self.__api_request('POST', url) | ||
487 | 470 | ||
488 | @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) | 471 | @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) |
489 | def status_unbookmark(self, id): | 472 | def status_unbookmark(self, id): |
@@ -493,8 +476,7 @@ class Mastodon(Internals): | |||
493 | Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked. | 476 | Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked. |
494 | """ | 477 | """ |
495 | id = self.__unpack_id(id) | 478 | id = self.__unpack_id(id) |
496 | url = '/api/v1/statuses/{0}/unbookmark'.format(str(id)) | 479 | return self.__api_request('POST', f'/api/v1/statuses/{id}/unbookmark') |
497 | return self.__api_request('POST', url) | ||
498 | 480 | ||
499 | ### | 481 | ### |
500 | # Writing data: Scheduled statuses | 482 | # Writing data: Scheduled statuses |
@@ -511,8 +493,7 @@ class Mastodon(Internals): | |||
511 | scheduled_at = self.__consistent_isoformat_utc(scheduled_at) | 493 | scheduled_at = self.__consistent_isoformat_utc(scheduled_at) |
512 | id = self.__unpack_id(id) | 494 | id = self.__unpack_id(id) |
513 | params = self.__generate_params(locals(), ['id']) | 495 | params = self.__generate_params(locals(), ['id']) |
514 | url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) | 496 | return self.__api_request('PUT', f'/api/v1/scheduled_statuses/{id}', params) |
515 | return self.__api_request('PUT', url, params) | ||
516 | 497 | ||
517 | @api_version("2.7.0", "2.7.0", "2.7.0") | 498 | @api_version("2.7.0", "2.7.0", "2.7.0") |
518 | def scheduled_status_delete(self, id): | 499 | def scheduled_status_delete(self, id): |
@@ -520,5 +501,4 @@ class Mastodon(Internals): | |||
520 | Deletes a scheduled status. | 501 | Deletes a scheduled status. |
521 | """ | 502 | """ |
522 | id = self.__unpack_id(id) | 503 | id = self.__unpack_id(id) |
523 | url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) | 504 | self.__api_request('DELETE', f'/api/v1/scheduled_statuses/{id}') |
524 | self.__api_request('DELETE', url) | ||