diff options
-rw-r--r-- | CHANGELOG.rst | 1 | ||||
-rw-r--r-- | docs/index.rst | 46 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 95 |
3 files changed, 122 insertions, 20 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 27a6341..b349f92 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst | |||
@@ -11,6 +11,7 @@ v1.5.1 (in progress, unreleased) | |||
11 | * New functions: `status_bookmark`, `status_unbookmark`, `bookmarks` | 11 | * New functions: `status_bookmark`, `status_unbookmark`, `bookmarks` |
12 | * New fine-grained oauth scopes: read:bookmarks and write:bookmarks. | 12 | * New fine-grained oauth scopes: read:bookmarks and write:bookmarks. |
13 | * Fixed missing notification type "poll" in push notification API and documentation.´ | 13 | * Fixed missing notification type "poll" in push notification API and documentation.´ |
14 | * Fixed a token loading bug | ||
14 | * Fix header upload in account_update_credentials (Thanks gdunstone) | 15 | * Fix header upload in account_update_credentials (Thanks gdunstone) |
15 | * Commented blocklist code (Thanks marnanel for the report) | 16 | * Commented blocklist code (Thanks marnanel for the report) |
16 | * Added fallback for when magic is not available (Thanks limburgher) | 17 | * Added fallback for when magic is not available (Thanks limburgher) |
diff --git a/docs/index.rst b/docs/index.rst index 47016ed..6a65b7b 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -791,7 +791,37 @@ Read marker dicts | |||
791 | 'version': # A counter that is incremented whenever the marker is set to a new status | 791 | 'version': # A counter that is incremented whenever the marker is set to a new status |
792 | 'updated_at': # The time the marker was last set, as a datetime object | 792 | 'updated_at': # The time the marker was last set, as a datetime object |
793 | } | 793 | } |
794 | 794 | ||
795 | Announcement dicts | ||
796 | ~~~~~~~~~~~~~~~~~~ | ||
797 | .. _announcement dict: | ||
798 | |||
799 | .. code-block:: python | ||
800 | |||
801 | mastodon.annoucements()[0] | ||
802 | # Returns the following dictionary: | ||
803 | { | ||
804 | 'id': # The annoucements id | ||
805 | 'content': # The contents of the annoucement, as an html string | ||
806 | 'starts_at': # The annoucements start time, as a datetime object. Can be None | ||
807 | 'ends_at': # The annoucements end time, as a datetime object. Can be None | ||
808 | 'all_day': # Boolean indicating whether the annoucement represents an "all day" event | ||
809 | 'published_at': # The annoucements publish time, as a datetime object | ||
810 | 'updated_at': # The annoucements last updated time, as a datetime object | ||
811 | 'read': # A boolean indicating whether the logged in user has dismissed the annoucement | ||
812 | 'mentions': # Users mentioned in the annoucement, as a list of mention dicts | ||
813 | 'tags': # Hashtags mentioned in the announcement, as a list of hashtag dicts | ||
814 | 'emojis': # Custom emoji used in the annoucement, as a list of emoji dicts | ||
815 | 'reactions': # Reactions to the annoucement, as a list of reaction dicts (documented inline here): | ||
816 | [ { | ||
817 | 'name': '# Name of the custom emoji or unicode emoji of the reaction | ||
818 | 'count': # Reaction counter (i.e. number of users who have added this reaction) | ||
819 | 'me': # True if the logged-in user has reacted with this emoji, false otherwise | ||
820 | 'url': # URL for the custom emoji image | ||
821 | 'static_url': # URL for a never-animated version of the custom emoji image | ||
822 | } ], | ||
823 | } | ||
824 | |||
795 | Admin account dicts | 825 | Admin account dicts |
796 | ~~~~~~~~~~~~~~~~~~~ | 826 | ~~~~~~~~~~~~~~~~~~~ |
797 | .. _admin account dict: | 827 | .. _admin account dict: |
@@ -1053,6 +1083,11 @@ Reading data: Preferences | |||
1053 | 1083 | ||
1054 | .. automethod:: Mastodon.preferences | 1084 | .. automethod:: Mastodon.preferences |
1055 | 1085 | ||
1086 | Reading data: Announcements | ||
1087 | -------------------------- | ||
1088 | |||
1089 | .. automethod:: Mastodon.announcements | ||
1090 | |||
1056 | 1091 | ||
1057 | Writing data: Statuses | 1092 | Writing data: Statuses |
1058 | ---------------------- | 1093 | ---------------------- |
@@ -1193,6 +1228,15 @@ for the logged-in user. | |||
1193 | .. automethod:: Mastodon.domain_block | 1228 | .. automethod:: Mastodon.domain_block |
1194 | .. automethod:: Mastodon.domain_unblock | 1229 | .. automethod:: Mastodon.domain_unblock |
1195 | 1230 | ||
1231 | |||
1232 | Writing data: Announcements | ||
1233 | --------------------------- | ||
1234 | These functions allow you to mark annoucements read and modify reactions. | ||
1235 | |||
1236 | .. automethod:: Mastodon.announcement_dismiss | ||
1237 | .. automethod:: Mastodon.announcement_reaction_create | ||
1238 | .. automethod:: Mastodon.announcement_reaction_delete | ||
1239 | |||
1196 | Pagination | 1240 | Pagination |
1197 | ---------- | 1241 | ---------- |
1198 | These functions allow for convenient retrieval of paginated data. | 1242 | These functions allow for convenient retrieval of paginated data. |
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5b676f3..a6ed111 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -216,6 +216,8 @@ class Mastodon: | |||
216 | __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("2.9.1", __DICT_VERSION_ACCOUNT) | 216 | __DICT_VERSION_ADMIN_ACCOUNT = bigger_version("2.9.1", __DICT_VERSION_ACCOUNT) |
217 | __DICT_VERSION_FEATURED_TAG = "3.0.0" | 217 | __DICT_VERSION_FEATURED_TAG = "3.0.0" |
218 | __DICT_VERSION_MARKER = "3.0.0" | 218 | __DICT_VERSION_MARKER = "3.0.0" |
219 | __DICT_VERSION_REACTION = "3.1.0" | ||
220 | __DICT_VERSION_ANNOUNCEMENT = bigger_version("3.1.0", __DICT_VERSION_REACTION) | ||
219 | 221 | ||
220 | ### | 222 | ### |
221 | # Registering apps | 223 | # Registering apps |
@@ -361,23 +363,6 @@ class Mastodon: | |||
361 | if not self.feature_set in ["mainline", "fedibird", "pleroma"]: | 363 | if not self.feature_set in ["mainline", "fedibird", "pleroma"]: |
362 | raise MastodonIllegalArgumentError('Requested invalid feature set') | 364 | raise MastodonIllegalArgumentError('Requested invalid feature set') |
363 | 365 | ||
364 | # Versioning | ||
365 | if mastodon_version == None: | ||
366 | self.retrieve_mastodon_version() | ||
367 | else: | ||
368 | try: | ||
369 | self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version) | ||
370 | except: | ||
371 | raise MastodonVersionError("Bad version specified") | ||
372 | |||
373 | if not version_check_mode in ["created", "changed", "none"]: | ||
374 | raise MastodonIllegalArgumentError("Invalid version check method.") | ||
375 | self.version_check_mode = version_check_mode | ||
376 | |||
377 | # Ratelimiting parameter check | ||
378 | if ratelimit_method not in ["throw", "wait", "pace"]: | ||
379 | raise MastodonIllegalArgumentError("Invalid ratelimit method.") | ||
380 | |||
381 | # Token loading | 366 | # Token loading |
382 | if self.client_id is not None: | 367 | if self.client_id is not None: |
383 | if os.path.isfile(self.client_id): | 368 | if os.path.isfile(self.client_id): |
@@ -405,7 +390,25 @@ class Mastodon: | |||
405 | if not (self.api_base_url is None or try_base_url == self.api_base_url): | 390 | if not (self.api_base_url is None or try_base_url == self.api_base_url): |
406 | raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') | 391 | raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') |
407 | self.api_base_url = try_base_url | 392 | self.api_base_url = try_base_url |
408 | 393 | ||
394 | # Versioning | ||
395 | if mastodon_version == None: | ||
396 | self.retrieve_mastodon_version() | ||
397 | else: | ||
398 | try: | ||
399 | self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version) | ||
400 | except: | ||
401 | raise MastodonVersionError("Bad version specified") | ||
402 | |||
403 | if not version_check_mode in ["created", "changed", "none"]: | ||
404 | raise MastodonIllegalArgumentError("Invalid version check method.") | ||
405 | self.version_check_mode = version_check_mode | ||
406 | |||
407 | # Ratelimiting parameter check | ||
408 | if ratelimit_method not in ["throw", "wait", "pace"]: | ||
409 | raise MastodonIllegalArgumentError("Invalid ratelimit method.") | ||
410 | |||
411 | |||
409 | def retrieve_mastodon_version(self): | 412 | def retrieve_mastodon_version(self): |
410 | """ | 413 | """ |
411 | Determine installed mastodon version and set major, minor and patch (not including RC info) accordingly. | 414 | Determine installed mastodon version and set major, minor and patch (not including RC info) accordingly. |
@@ -1594,6 +1597,20 @@ class Mastodon: | |||
1594 | return self.__api_request('GET', '/api/v1/preferences') | 1597 | return self.__api_request('GET', '/api/v1/preferences') |
1595 | 1598 | ||
1596 | ## | 1599 | ## |
1600 | # Reading data: Announcements | ||
1601 | ## | ||
1602 | |||
1603 | #/api/v1/announcements | ||
1604 | @api_version("3.1.0", "3.1.0", __DICT_VERSION_ANNOUNCEMENT) | ||
1605 | def announcements(self): | ||
1606 | """ | ||
1607 | Fetch currently active annoucements. | ||
1608 | |||
1609 | Returns a list of `annoucement dicts`_. | ||
1610 | """ | ||
1611 | return self.__api_request('GET', '/api/v1/announcements') | ||
1612 | |||
1613 | ## | ||
1597 | # Reading data: Read markers | 1614 | # Reading data: Read markers |
1598 | ## | 1615 | ## |
1599 | @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER) | 1616 | @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER) |
@@ -2643,7 +2660,47 @@ class Mastodon: | |||
2643 | Remove the current push subscription the logged-in user has for this app. | 2660 | Remove the current push subscription the logged-in user has for this app. |
2644 | """ | 2661 | """ |
2645 | self.__api_request('DELETE', '/api/v1/push/subscription') | 2662 | self.__api_request('DELETE', '/api/v1/push/subscription') |
2663 | |||
2664 | ### | ||
2665 | # Writing data: Annoucements | ||
2666 | ### | ||
2667 | @api_version("3.1.0", "3.1.0", "3.1.0") | ||
2668 | def announcement_dismiss(self, id): | ||
2669 | """ | ||
2670 | Set the given annoucement to read. | ||
2671 | """ | ||
2672 | id = self.__unpack_id(id) | ||
2673 | |||
2674 | url = '/api/v1/announcements/{0}/dismiss'.format(str(id)) | ||
2675 | self.__api_request('POST', url) | ||
2676 | |||
2677 | @api_version("3.1.0", "3.1.0", "3.1.0") | ||
2678 | def announcement_reaction_create(self, id, reaction): | ||
2679 | """ | ||
2680 | Add a reaction to an announcement. `reaction` can either be a unicode emoji | ||
2681 | or the name of one of the instances custom emoji. | ||
2682 | |||
2683 | Will throw an API error if the reaction name is not one of the allowed things | ||
2684 | or when trying to add a reaction that the user has already added (adding a | ||
2685 | reaction that a different user added is legal and increments the count). | ||
2686 | """ | ||
2687 | id = self.__unpack_id(id) | ||
2688 | |||
2689 | url = '/api/v1/announcements/{0}/reactions/{1}'.format(str(id), reaction) | ||
2690 | self.__api_request('PUT', url) | ||
2646 | 2691 | ||
2692 | @api_version("3.1.0", "3.1.0", "3.1.0") | ||
2693 | def announcement_reaction_delete(self, id, reaction): | ||
2694 | """ | ||
2695 | Remove a reaction to an announcement. | ||
2696 | |||
2697 | Will throw an API error if the reaction does not exist. | ||
2698 | """ | ||
2699 | id = self.__unpack_id(id) | ||
2700 | |||
2701 | url = '/api/v1/announcements/{0}/reactions/{1}'.format(str(id), reaction) | ||
2702 | self.__api_request('DELETE', url) | ||
2703 | |||
2647 | ### | 2704 | ### |
2648 | # Moderation API | 2705 | # Moderation API |
2649 | ### | 2706 | ### |
@@ -3151,7 +3208,7 @@ class Mastodon: | |||
3151 | """ | 3208 | """ |
3152 | Parse dates in certain known json fields, if possible. | 3209 | Parse dates in certain known json fields, if possible. |
3153 | """ | 3210 | """ |
3154 | known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at", "updated_at", "last_status_at"] | 3211 | known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at", "updated_at", "last_status_at", "starts_at", "ends_at", "published_at"] |
3155 | for k, v in json_object.items(): | 3212 | for k, v in json_object.items(): |
3156 | if k in known_date_fields: | 3213 | if k in known_date_fields: |
3157 | if v != None: | 3214 | if v != None: |