From 8512157c9a530057dc3b76c9558b79e51f277a76 Mon Sep 17 00:00:00 2001 From: jfm Date: Fri, 3 May 2024 08:58:55 +0200 Subject: [PATCH] Added undoing favourite and boost --- .coverage | Bin 53248 -> 53248 bytes src/mastodon/statuses.py | 25 ++++ tests/resources/unfavourite_response.json | 142 ++++++++++++++++++++++ tests/resources/unreblog_response.json | 142 ++++++++++++++++++++++ tests/test_statuses.py | 25 ++++ 5 files changed, 334 insertions(+) create mode 100644 tests/resources/unfavourite_response.json create mode 100644 tests/resources/unreblog_response.json diff --git a/.coverage b/.coverage index 3a8c3edccc93d09109bfd99b795edc35c5589568..463cb35e89551cb70c408dd2a40dbf6272567389 100644 GIT binary patch delta 97 zcmV-n0G|JVpaX!Q1F!~wCN%&L_7Cn4`O6nl%IeH~x40Px-I$pW@%ozlDD_|04cb{C)gw{8jt~{K@>${C@n_ vn*{~<`6rw93-fRbvM_Q=2>#ny|AT#Ucz-H4CmT>egzZ`E@zTww`pp~wR4W|? diff --git a/src/mastodon/statuses.py b/src/mastodon/statuses.py index 2450c64..8040cf8 100644 --- a/src/mastodon/statuses.py +++ b/src/mastodon/statuses.py @@ -19,6 +19,19 @@ class Statuses(): else: raise RuntimeError("Server returned {} {}".format(response.status_code, response.content)) + def unfavourite(self, status_id): + server = self.config.get_value("server") + url = f"https://{server}/api/v1/statuses/{status_id}/unfavourite" + + response = requests.post(url, headers=self.auth.get_auth_headers()) + + logger.trace("JSON: {}".format(str(response.content))) + if response.status_code == 200: + return response.json() + else: + raise RuntimeError("Server returned {} {}".format(response.status_code, response.content)) + + def reblog(self, status_id): server = self.config.get_value("server") url = f"https://{server}/api/v1/statuses/{status_id}/reblog" @@ -30,3 +43,15 @@ class Statuses(): return response.json() else: raise RuntimeError("Server returned {} {}".format(response.status_code, response.content)) + + def unreblog(self, status_id): + server = self.config.get_value("server") + url = f"https://{server}/api/v1/statuses/{status_id}/unreblog" + + response = requests.post(url, headers=self.auth.get_auth_headers()) + + logger.trace("JSON: {}".format(str(response.content))) + if response.status_code == 200: + return response.json() + else: + raise RuntimeError("Server returned {} {}".format(response.status_code, response.content)) diff --git a/tests/resources/unfavourite_response.json b/tests/resources/unfavourite_response.json new file mode 100644 index 0000000..e93e0d0 --- /dev/null +++ b/tests/resources/unfavourite_response.json @@ -0,0 +1,142 @@ +{ + "id": "103270115826048975", + "created_at": "2019-12-08T03:48:33.901Z", + "in_reply_to_id": null, + "in_reply_to_account_id": null, + "sensitive": false, + "spoiler_text": "", + "visibility": "public", + "language": "en", + "uri": "https://mastodon.social/users/Gargron/statuses/103270115826048975", + "url": "https://mastodon.social/@Gargron/103270115826048975", + "replies_count": 5, + "reblogs_count": 6, + "favourites_count": 11, + "favourited": false, + "reblogged": false, + "muted": false, + "bookmarked": false, + "content": "

"I lost my inheritance with one wrong digit on my sort code"

https://www.theguardian.com/money/2019/dec/07/i-lost-my-193000-inheritance-with-one-wrong-digit-on-my-sort-code", + "reblog": null, + "application": { + "name": "Web", + "website": null + }, + "account": { + "id": "1", + "username": "Gargron", + "acct": "Gargron", + "display_name": "Eugen", + "locked": false, + "bot": false, + "discoverable": true, + "group": false, + "created_at": "2016-03-16T14:34:26.392Z", + "note": "

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

", + "url": "https://mastodon.social/@Gargron", + "avatar": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg", + "avatar_static": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg", + "header": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png", + "header_static": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png", + "followers_count": 322930, + "following_count": 459, + "statuses_count": 61323, + "last_status_at": "2019-12-10T08:14:44.811Z", + "emojis": [], + "fields": [ + { + "name": "Patreon", + "value": "https://www.patreon.com/mastodonhttps://zeonfederated.com"I lost my inheritance with one wrong digit on my sort code"

https://www.theguardian.com/money/2019/dec/07/i-lost-my-193000-inheritance-with-one-wrong-digit-on-my-sort-code", + "reblog": null, + "application": { + "name": "Web", + "website": null + }, + "account": { + "id": "1", + "username": "Gargron", + "acct": "Gargron", + "display_name": "Eugen", + "locked": false, + "bot": false, + "discoverable": true, + "group": false, + "created_at": "2016-03-16T14:34:26.392Z", + "note": "

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

", + "url": "https://mastodon.social/@Gargron", + "avatar": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg", + "avatar_static": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg", + "header": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png", + "header_static": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png", + "followers_count": 322930, + "following_count": 459, + "statuses_count": 61323, + "last_status_at": "2019-12-10T08:14:44.811Z", + "emojis": [], + "fields": [ + { + "name": "Patreon", + "value": "https://www.patreon.com/mastodonhttps://zeonfederated.com