From f6d12aa5b1cc1dffcff31d1af1b0b58d9ecd4c1e Mon Sep 17 00:00:00 2001 From: halcy Date: Wed, 23 Nov 2022 23:48:38 +0200 Subject: Fix search issue, add pathlib path support --- CHANGELOG.rst | 2 ++ mastodon/Mastodon.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39c5e66..a928586 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,8 @@ v1.7.0 * Add missing streaming events * Add missing parameters on directory endpoint (thanks heharkon) * This isn't somehing I changed but thank you a / triggerofsol for answering Many questions I had about specifics of what the API does that are not documented +* Fixed search ignoring `exclude_unreviewed` (Thanks acidghost) +* Add support for using pathlib paths when loading media files (Thanks reagle) * TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma. v1.6.3 diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 99133cf..7e9f06f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -57,6 +57,12 @@ try: except ImportError: magic = None +try: + from pathlib import PurePath +except: + class PurePath: + pass + ### # Version check functions, including decorator and parser ### @@ -1450,7 +1456,8 @@ class Mastodon: `offset`, `min_id` and `max_id` can be used to paginate. `exclude_unreviewed` can be used to restrict search results for hashtags to only - those that have been reviewed by moderators. It is on by default. + those that have been reviewed by moderators. It is on by default. When using the + v1 search API (pre 2.4.1), it is ignored. Will use search_v1 (no tag dicts in return values) on Mastodon versions before 2.4.1), search_v2 otherwise. Parameters other than resolve are only available @@ -1461,7 +1468,7 @@ class Mastodon: Returns a `search result dict`_, with tags as `hashtag dicts`_. """ if self.verify_minimum_version("2.4.1", cached=True): - return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id) + return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id, exclude_unreviewed=exclude_unreviewed) else: self.__ensure_search_params_acceptable( account_id, offset, min_id, max_id) @@ -4101,6 +4108,8 @@ class Mastodon: return mime_type def __load_media_file(self, media_file, mime_type=None, file_name=None): + if isinstance(media_file, PurePath): + media_file = str(media_file) if isinstance(media_file, str) and os.path.isfile(media_file): mime_type = self.__guess_type(media_file) media_file = open(media_file, 'rb') -- cgit v1.2.3