kopia lustrzana https://github.com/halcy/Mastodon.py
Merge branch 'master' of github.com:halcy/Mastodon.py
commit
137cf49435
|
@ -64,6 +64,7 @@ from .push import Mastodon as Push
|
||||||
from .admin import Mastodon as Admin
|
from .admin import Mastodon as Admin
|
||||||
from .streaming_endpoints import Mastodon as Streaming
|
from .streaming_endpoints import Mastodon as Streaming
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# The actual Mastodon class
|
# The actual Mastodon class
|
||||||
#
|
#
|
||||||
|
|
|
@ -9,6 +9,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
@api_version("2.7.0", "2.7.0", "3.4.0")
|
@api_version("2.7.0", "2.7.0", "3.4.0")
|
||||||
def create_account(self, username, password, email, agreement=False, reason=None, locale="en", scopes=_DEFAULT_SCOPES, to_file=None, return_detailed_error=False):
|
def create_account(self, username, password, email, agreement=False, reason=None, locale="en", scopes=_DEFAULT_SCOPES, to_file=None, return_detailed_error=False):
|
||||||
|
@ -348,7 +349,6 @@ class Mastodon(Internals):
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', f'/api/v1/accounts/{id}/remove_from_followers')
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/remove_from_followers')
|
||||||
|
|
||||||
|
|
||||||
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_block(self, id):
|
def account_block(self, id):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Moderation API
|
# Moderation API
|
||||||
|
@ -377,7 +378,7 @@ class Mastodon(Internals):
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', f'/api/v1/admin/domain_blocks/{id}')
|
return self.__api_request('GET', f'/api/v1/admin/domain_blocks/{id}')
|
||||||
else:
|
else:
|
||||||
params = self.__generate_params(locals(),['limit'])
|
params = self.__generate_params(locals(), ['limit'])
|
||||||
return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params)
|
return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params)
|
||||||
|
|
||||||
@api_version("4.0.0", "4.0.0", _DICT_VERSION_ADMIN_DOMAIN_BLOCK)
|
@api_version("4.0.0", "4.0.0", _DICT_VERSION_ADMIN_DOMAIN_BLOCK)
|
||||||
|
|
|
@ -14,6 +14,7 @@ from .utility import parse_version_string, api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Registering apps
|
# Registering apps
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Conversations
|
# Reading data: Conversations
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Endorsements
|
# Reading data: Endorsements
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Favourites
|
# Reading data: Favourites
|
||||||
|
@ -59,4 +60,3 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
params = self.__generate_params(locals())
|
params = self.__generate_params(locals())
|
||||||
return self.__api_request('GET', '/api/v1/bookmarks', params)
|
return self.__api_request('GET', '/api/v1/bookmarks', params)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Keyword filters
|
# Reading data: Keyword filters
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Featured hashtags
|
# Reading data: Featured hashtags
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .compat import urlparse
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Instances
|
# Reading data: Instances
|
||||||
|
|
|
@ -22,6 +22,7 @@ from .errors import MastodonNetworkError, MastodonIllegalArgumentError, Mastodon
|
||||||
from .compat import urlparse, magic, PurePath
|
from .compat import urlparse, magic, PurePath
|
||||||
from .defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SEC
|
from .defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SEC
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Internal helpers, dragons probably
|
# Internal helpers, dragons probably
|
||||||
###
|
###
|
||||||
|
@ -37,7 +38,6 @@ class Mastodon():
|
||||||
date_time = date_time.replace(tzinfo=datetime.timezone.utc)
|
date_time = date_time.replace(tzinfo=datetime.timezone.utc)
|
||||||
return date_time.timestamp()
|
return date_time.timestamp()
|
||||||
|
|
||||||
|
|
||||||
def __get_logged_in_id(self):
|
def __get_logged_in_id(self):
|
||||||
"""
|
"""
|
||||||
Fetch the logged in user's ID, with caching. ID is reset on calls to log_in.
|
Fetch the logged in user's ID, with caching. ID is reset on calls to log_in.
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Lists
|
# Reading data: Lists
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Media
|
# Reading data: Media
|
||||||
|
|
|
@ -6,6 +6,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Notifications
|
# Reading data: Notifications
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Polls
|
# Reading data: Polls
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Preferences
|
# Reading data: Preferences
|
||||||
|
@ -68,4 +69,3 @@ class Mastodon(Internals):
|
||||||
params[timeline]["last_read_id"] = self.__unpack_id(last_read_id)
|
params[timeline]["last_read_id"] = self.__unpack_id(last_read_id)
|
||||||
|
|
||||||
return self.__api_request('POST', '/api/v1/markers', params, use_json=True)
|
return self.__api_request('POST', '/api/v1/markers', params, use_json=True)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from .compat import IMPL_HAS_ECE, http_ece
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Webpush subscriptions
|
# Reading data: Webpush subscriptions
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Mutes and Blocks
|
# Reading data: Mutes and Blocks
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Reports
|
# Reading data: Reports
|
||||||
|
|
|
@ -6,6 +6,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Searching
|
# Reading data: Searching
|
||||||
|
|
|
@ -9,6 +9,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Statuses
|
# Reading data: Statuses
|
||||||
|
@ -272,7 +273,7 @@ class Mastodon(Internals):
|
||||||
return self.status_post(status)
|
return self.status_post(status)
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS)
|
||||||
def status_update(self, id, status = None, spoiler_text = None, sensitive = None, media_ids = None, poll = None):
|
def status_update(self, id, status=None, spoiler_text=None, sensitive=None, media_ids=None, poll=None):
|
||||||
"""
|
"""
|
||||||
Edit a status. The meanings of the fields are largely the same as in :ref:`status_post() <status_post()>`,
|
Edit a status. The meanings of the fields are largely the same as in :ref:`status_post() <status_post()>`,
|
||||||
though not every field can be edited.
|
though not every field can be edited.
|
||||||
|
@ -280,12 +281,12 @@ class Mastodon(Internals):
|
||||||
Note that editing a poll will reset the votes.
|
Note that editing a poll will reset the votes.
|
||||||
"""
|
"""
|
||||||
return self.__status_internal(
|
return self.__status_internal(
|
||||||
status = status,
|
status=status,
|
||||||
media_ids = media_ids,
|
media_ids=media_ids,
|
||||||
sensitive = sensitive,
|
sensitive=sensitive,
|
||||||
spoiler_text = spoiler_text,
|
spoiler_text=spoiler_text,
|
||||||
poll = poll,
|
poll=poll,
|
||||||
edit = id
|
edit=id
|
||||||
)
|
)
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS_EDIT)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS_EDIT)
|
||||||
|
@ -317,7 +318,7 @@ class Mastodon(Internals):
|
||||||
scheduled_at=None, poll=None, untag=False):
|
scheduled_at=None, poll=None, untag=False):
|
||||||
"""
|
"""
|
||||||
Helper function - acts like status_post, but prepends the name of all
|
Helper function - acts like status_post, but prepends the name of all
|
||||||
the users that are being replied to to the status text and retains
|
the users that are being replied to the status text and retains
|
||||||
CW and visibility if not explicitly overridden.
|
CW and visibility if not explicitly overridden.
|
||||||
|
|
||||||
Note that `to_status` should be a :ref:`status dict <status dict>` and not an ID.
|
Note that `to_status` should be a :ref:`status dict <status dict>` and not an ID.
|
||||||
|
|
|
@ -217,6 +217,7 @@ class StreamListener(object):
|
||||||
else:
|
else:
|
||||||
handler(name, payload)
|
handler(name, payload)
|
||||||
|
|
||||||
|
|
||||||
class CallbackStreamListener(StreamListener):
|
class CallbackStreamListener(StreamListener):
|
||||||
"""
|
"""
|
||||||
Simple callback stream handler class.
|
Simple callback stream handler class.
|
||||||
|
@ -227,20 +228,19 @@ class CallbackStreamListener(StreamListener):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
update_handler=None,
|
update_handler=None,
|
||||||
local_update_handler=None,
|
local_update_handler=None,
|
||||||
delete_handler=None,
|
delete_handler=None,
|
||||||
notification_handler=None,
|
notification_handler=None,
|
||||||
conversation_handler=None,
|
conversation_handler=None,
|
||||||
unknown_event_handler=None,
|
unknown_event_handler=None,
|
||||||
status_update_handler=None,
|
status_update_handler=None,
|
||||||
filters_changed_handler=None,
|
filters_changed_handler=None,
|
||||||
announcement_handler=None,
|
announcement_handler=None,
|
||||||
announcement_reaction_handler=None,
|
announcement_reaction_handler=None,
|
||||||
announcement_delete_handler=None,
|
announcement_delete_handler=None,
|
||||||
encryted_message_handler=None
|
encryted_message_handler=None
|
||||||
|
):
|
||||||
):
|
|
||||||
super(CallbackStreamListener, self).__init__()
|
super(CallbackStreamListener, self).__init__()
|
||||||
self.update_handler = update_handler
|
self.update_handler = update_handler
|
||||||
self.local_update_handler = local_update_handler
|
self.local_update_handler = local_update_handler
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Streaming
|
# Streaming
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Follow suggestions
|
# Reading data: Follow suggestions
|
||||||
|
|
|
@ -6,6 +6,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Timelines
|
# Reading data: Timelines
|
||||||
|
@ -101,4 +102,3 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.timeline(f'list/{id}', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
|
return self.timeline(f'list/{id}', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .utility import api_version
|
||||||
|
|
||||||
from .internals import Mastodon as Internals
|
from .internals import Mastodon as Internals
|
||||||
|
|
||||||
|
|
||||||
class Mastodon(Internals):
|
class Mastodon(Internals):
|
||||||
###
|
###
|
||||||
# Reading data: Trends
|
# Reading data: Trends
|
||||||
|
|
|
@ -24,10 +24,12 @@ def parse_version_string(version_string):
|
||||||
)
|
)
|
||||||
return version_parts
|
return version_parts
|
||||||
|
|
||||||
|
|
||||||
def max_version(*version_strings):
|
def max_version(*version_strings):
|
||||||
"""Returns the maximum version of all provided version strings."""
|
"""Returns the maximum version of all provided version strings."""
|
||||||
return max(version_strings, key=parse_version_string)
|
return max(version_strings, key=parse_version_string)
|
||||||
|
|
||||||
|
|
||||||
def api_version(created_ver, last_changed_ver, return_value_ver):
|
def api_version(created_ver, last_changed_ver, return_value_ver):
|
||||||
"""Version check decorator. Currently only checks Bigger Than."""
|
"""Version check decorator. Currently only checks Bigger Than."""
|
||||||
def api_min_version_decorator(function):
|
def api_min_version_decorator(function):
|
||||||
|
@ -49,6 +51,7 @@ def api_version(created_ver, last_changed_ver, return_value_ver):
|
||||||
return decorate(function, wrapper)
|
return decorate(function, wrapper)
|
||||||
return api_min_version_decorator
|
return api_min_version_decorator
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Dict helper class.
|
# Dict helper class.
|
||||||
# Defined at top level so it can be pickled.
|
# Defined at top level so it can be pickled.
|
||||||
|
|
Ładowanie…
Reference in New Issue