kopia lustrzana https://github.com/halcy/Mastodon.py
Format code with PEP 8 standards
rodzic
9225072cc8
commit
68ac32b6be
|
@ -64,13 +64,14 @@ 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
|
||||||
#
|
#
|
||||||
# Almost all code is now imported from smaller files to make editing a bit more pleasant
|
# Almost all code is now imported from smaller files to make editing a bit more pleasant
|
||||||
###
|
###
|
||||||
class Mastodon(Utility, Authentication, Accounts, Instance, Timeline, Statuses, Polls, Notifications, Hashtags,
|
class Mastodon(Utility, Authentication, Accounts, Instance, Timeline, Statuses, Polls, Notifications, Hashtags,
|
||||||
Filters, Suggestions, Endorsements, Relationships, Lists, Trends, Search, Favourites, Reports,
|
Filters, Suggestions, Endorsements, Relationships, Lists, Trends, Search, Favourites, Reports,
|
||||||
Preferences, Push, Admin, Conversations, Media, Streaming):
|
Preferences, Push, Admin, Conversations, Media, Streaming):
|
||||||
"""
|
"""
|
||||||
Thorough and easy to use Mastodon
|
Thorough and easy to use Mastodon
|
||||||
|
|
|
@ -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):
|
||||||
|
@ -16,8 +17,8 @@ class Mastodon(Internals):
|
||||||
Creates a new user account with the given username, password and email. "agreement"
|
Creates a new user account with the given username, password and email. "agreement"
|
||||||
must be set to true (after showing the user the instance's user agreement and having
|
must be set to true (after showing the user the instance's user agreement and having
|
||||||
them agree to it), "locale" specifies the language for the confirmation email as an
|
them agree to it), "locale" specifies the language for the confirmation email as an
|
||||||
ISO 639-1 (two letter) or, if a language does not have one, 639-3 (three letter) language
|
ISO 639-1 (two letter) or, if a language does not have one, 639-3 (three letter) language
|
||||||
code. `reason` can be used to specify why a user would like to join if approved-registrations
|
code. `reason` can be used to specify why a user would like to join if approved-registrations
|
||||||
mode is on.
|
mode is on.
|
||||||
|
|
||||||
Does not require an access token, but does require a client grant.
|
Does not require an access token, but does require a client grant.
|
||||||
|
@ -30,11 +31,11 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
By default, the function will throw if the account could not be created. Alternately,
|
By default, the function will throw if the account could not be created. Alternately,
|
||||||
when `return_detailed_error` is passed, Mastodon.py will return the detailed error
|
when `return_detailed_error` is passed, Mastodon.py will return the detailed error
|
||||||
response that the API provides (Starting from version 3.4.0 - not checked here) as an dict with
|
response that the API provides (Starting from version 3.4.0 - not checked here) as an dict with
|
||||||
error details as the second return value and the token returned as `None` in case of error.
|
error details as the second return value and the token returned as `None` in case of error.
|
||||||
The dict will contain a text `error` values as well as a `details` value which is a dict with
|
The dict will contain a text `error` values as well as a `details` value which is a dict with
|
||||||
one optional key for each potential field (`username`, `password`, `email` and `agreement`),
|
one optional key for each potential field (`username`, `password`, `email` and `agreement`),
|
||||||
each if present containing a dict with an `error` category and free text `description`.
|
each if present containing a dict with an `error` category and free text `description`.
|
||||||
Valid error categories are:
|
Valid error categories are:
|
||||||
|
|
||||||
* ERR_BLOCKED - When e-mail provider is not allowed
|
* ERR_BLOCKED - When e-mail provider is not allowed
|
||||||
|
@ -77,7 +78,7 @@ class Mastodon(Internals):
|
||||||
raise MastodonIllegalArgumentError(f'Invalid request: {e}')
|
raise MastodonIllegalArgumentError(f'Invalid request: {e}')
|
||||||
self.access_token = response['access_token']
|
self.access_token = response['access_token']
|
||||||
self.__set_refresh_token(response.get('refresh_token'))
|
self.__set_refresh_token(response.get('refresh_token'))
|
||||||
self.__set_token_expired(int(response.get('expires_in', 0)))
|
self.__set_token_expired(int(response.get('expires_in', 0)))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonIllegalArgumentError('Invalid request')
|
raise MastodonIllegalArgumentError('Invalid request')
|
||||||
|
|
||||||
|
@ -274,14 +275,14 @@ class Mastodon(Internals):
|
||||||
def account_lookup(self, acct):
|
def account_lookup(self, acct):
|
||||||
"""
|
"""
|
||||||
Look up an account from user@instance form (@instance allowed but not required for
|
Look up an account from user@instance form (@instance allowed but not required for
|
||||||
local accounts). Will only return accounts that the instance already knows about,
|
local accounts). Will only return accounts that the instance already knows about,
|
||||||
and not do any webfinger requests. Use `account_search` if you need to resolve users
|
and not do any webfinger requests. Use `account_search` if you need to resolve users
|
||||||
through webfinger from remote.
|
through webfinger from remote.
|
||||||
|
|
||||||
Returns an :ref:`account dict <account dict>`.
|
Returns an :ref:`account dict <account dict>`.
|
||||||
"""
|
"""
|
||||||
return self.__api_request('GET', '/api/v1/accounts/lookup', self.__generate_params(locals()))
|
return self.__api_request('GET', '/api/v1/accounts/lookup', self.__generate_params(locals()))
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_FAMILIAR_FOLLOWERS)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_FAMILIAR_FOLLOWERS)
|
||||||
def account_familiar_followers(self, id):
|
def account_familiar_followers(self, id):
|
||||||
"""
|
"""
|
||||||
|
@ -347,7 +348,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,12 +7,13 @@ 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
|
||||||
###
|
###
|
||||||
@api_version("2.9.1", "4.0.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
@api_version("2.9.1", "4.0.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
||||||
def admin_accounts_v2(self, origin=None, by_domain=None, status=None, username=None, display_name=None, email=None, ip=None,
|
def admin_accounts_v2(self, origin=None, by_domain=None, status=None, username=None, display_name=None, email=None, ip=None,
|
||||||
permissions=None, invited_by=None, role_ids=None, max_id=None, min_id=None, since_id=None, limit=None):
|
permissions=None, invited_by=None, role_ids=None, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
"""
|
"""
|
||||||
Fetches a list of accounts that match given criteria. By default, local accounts are returned.
|
Fetches a list of accounts that match given criteria. By default, local accounts are returned.
|
||||||
|
@ -65,8 +66,8 @@ class Mastodon(Internals):
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
|
||||||
def admin_accounts(self, remote=False, by_domain=None, status='active', username=None, display_name=None, email=None, ip=None, staff_only=False, max_id=None, min_id=None, since_id=None, limit=None):
|
def admin_accounts(self, remote=False, by_domain=None, status='active', username=None, display_name=None, email=None, ip=None, staff_only=False, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
"""
|
"""
|
||||||
Currently a synonym for admin_accounts_v1, now deprecated. You are strongly encouraged to use admin_accounts_v2 instead, since this one is kind of bad.
|
Currently a synonym for admin_accounts_v1, now deprecated. You are strongly encouraged to use admin_accounts_v2 instead, since this one is kind of bad.
|
||||||
|
|
||||||
!!!!! This function may be switched to calling the v2 API in the future. This is your warning. If you want to keep using v1, use it explicitly. !!!!!
|
!!!!! This function may be switched to calling the v2 API in the future. This is your warning. If you want to keep using v1, use it explicitly. !!!!!
|
||||||
"""
|
"""
|
||||||
return self.admin_accounts_v1(
|
return self.admin_accounts_v1(
|
||||||
|
@ -377,16 +378,16 @@ 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)
|
||||||
def admin_create_domain_block(self, domain:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None):
|
def admin_create_domain_block(self, domain:str, severity:str=None, reject_media:bool=None, reject_reports:bool=None, private_comment:str=None, public_comment:str=None, obfuscate:bool=None):
|
||||||
"""
|
"""
|
||||||
Perform a moderation action on a domain. Requires scope `admin:write:domain_blocks`.
|
Perform a moderation action on a domain. Requires scope `admin:write:domain_blocks`.
|
||||||
|
|
||||||
Valid severities are:
|
Valid severities are:
|
||||||
* "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user.
|
* "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user.
|
||||||
* "suspend" - deny interactions with this instance going forward. This action is reversible.
|
* "suspend" - deny interactions with this instance going forward. This action is reversible.
|
||||||
* "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending..
|
* "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending..
|
||||||
|
|
||||||
|
@ -411,7 +412,7 @@ class Mastodon(Internals):
|
||||||
Modify existing moderation action on a domain. Requires scope `admin:write:domain_blocks`.
|
Modify existing moderation action on a domain. Requires scope `admin:write:domain_blocks`.
|
||||||
|
|
||||||
Valid severities are:
|
Valid severities are:
|
||||||
* "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user.
|
* "silence" - hide all posts from federated timelines and do not show notifications to local users from the remote instance's users unless they are following the remote user.
|
||||||
* "suspend" - deny interactions with this instance going forward. This action is reversible.
|
* "suspend" - deny interactions with this instance going forward. This action is reversible.
|
||||||
* "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.
|
* "limit" - generally used with reject_media=true to force reject media from an instance without silencing or suspending.
|
||||||
|
|
||||||
|
@ -481,7 +482,7 @@ class Mastodon(Internals):
|
||||||
for key in ["active_users", "new_users", "interactions", "opened_reports", "resolved_reports"]:
|
for key in ["active_users", "new_users", "interactions", "opened_reports", "resolved_reports"]:
|
||||||
if params_init[key] == True:
|
if params_init[key] == True:
|
||||||
keys.append(key)
|
keys.append(key)
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
for key in ["tag_accounts", "tag_uses", "tag_servers"]:
|
for key in ["tag_accounts", "tag_uses", "tag_servers"]:
|
||||||
if params_init[key] is not None:
|
if params_init[key] is not None:
|
||||||
|
@ -498,7 +499,7 @@ class Mastodon(Internals):
|
||||||
params["keys"] = keys
|
params["keys"] = keys
|
||||||
params["start_at"] = self.__consistent_isoformat_utc(start_at)
|
params["start_at"] = self.__consistent_isoformat_utc(start_at)
|
||||||
params["end_at"] = self.__consistent_isoformat_utc(end_at)
|
params["end_at"] = self.__consistent_isoformat_utc(end_at)
|
||||||
|
|
||||||
return self.__api_request('POST', '/api/v1/admin/measures', params, use_json=True)
|
return self.__api_request('POST', '/api/v1/admin/measures', params, use_json=True)
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_ADMIN_DIMENSION)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_ADMIN_DIMENSION)
|
||||||
|
@ -531,7 +532,7 @@ class Mastodon(Internals):
|
||||||
for key in ["languages", "sources", "servers", "space_usage", "software_versions"]:
|
for key in ["languages", "sources", "servers", "space_usage", "software_versions"]:
|
||||||
if params_init[key] == True:
|
if params_init[key] == True:
|
||||||
keys.append(key)
|
keys.append(key)
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
for key in ["tag_servers", "tag_languages"]:
|
for key in ["tag_servers", "tag_languages"]:
|
||||||
if params_init[key] is not None:
|
if params_init[key] is not None:
|
||||||
|
@ -550,7 +551,7 @@ class Mastodon(Internals):
|
||||||
params["limit"] = limit
|
params["limit"] = limit
|
||||||
params["start_at"] = self.__consistent_isoformat_utc(start_at)
|
params["start_at"] = self.__consistent_isoformat_utc(start_at)
|
||||||
params["end_at"] = self.__consistent_isoformat_utc(end_at)
|
params["end_at"] = self.__consistent_isoformat_utc(end_at)
|
||||||
|
|
||||||
return self.__api_request('POST', '/api/v1/admin/dimensions', params, use_json=True)
|
return self.__api_request('POST', '/api/v1/admin/dimensions', params, use_json=True)
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_ADMIN_RETENTION)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_ADMIN_RETENTION)
|
||||||
|
@ -568,4 +569,4 @@ class Mastodon(Internals):
|
||||||
"end_at": self.__consistent_isoformat_utc(end_at),
|
"end_at": self.__consistent_isoformat_utc(end_at),
|
||||||
"frequency": frequency
|
"frequency": frequency
|
||||||
}
|
}
|
||||||
return self.__api_request('POST', '/api/v1/admin/retention', params)
|
return self.__api_request('POST', '/api/v1/admin/retention', params)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -43,7 +44,7 @@ class Mastodon(Internals):
|
||||||
Returns `client_id` and `client_secret`, both as strings.
|
Returns `client_id` and `client_secret`, both as strings.
|
||||||
"""
|
"""
|
||||||
if api_base_url is None:
|
if api_base_url is None:
|
||||||
raise MastodonIllegalArgumentError("API base URL is required.")
|
raise MastodonIllegalArgumentError("API base URL is required.")
|
||||||
api_base_url = Mastodon.__protocolize(api_base_url)
|
api_base_url = Mastodon.__protocolize(api_base_url)
|
||||||
|
|
||||||
request_data = {
|
request_data = {
|
||||||
|
@ -86,9 +87,9 @@ class Mastodon(Internals):
|
||||||
version_check_mode="created", session=None, feature_set="mainline", user_agent="mastodonpy", lang=None):
|
version_check_mode="created", session=None, feature_set="mainline", user_agent="mastodonpy", lang=None):
|
||||||
"""
|
"""
|
||||||
Create a new API wrapper instance based on the given `client_secret` and `client_id` on the
|
Create a new API wrapper instance based on the given `client_secret` and `client_id` on the
|
||||||
instance given by `api_base_url`. If you give a `client_id` and it is not a file, you must
|
instance given by `api_base_url`. If you give a `client_id` and it is not a file, you must
|
||||||
also give a secret. If you specify an `access_token` then you don't need to specify a `client_id`.
|
also give a secret. If you specify an `access_token` then you don't need to specify a `client_id`.
|
||||||
It is allowed to specify neither - in this case, you will be restricted to only using endpoints
|
It is allowed to specify neither - in this case, you will be restricted to only using endpoints
|
||||||
that do not require authentication. If a file is given as `client_id`, client ID, secret and
|
that do not require authentication. If a file is given as `client_id`, client ID, secret and
|
||||||
base url are read from that file.
|
base url are read from that file.
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
# Verify we have a base URL, protocolize
|
# Verify we have a base URL, protocolize
|
||||||
if self.api_base_url is None:
|
if self.api_base_url is None:
|
||||||
raise MastodonIllegalArgumentError("API base URL is required.")
|
raise MastodonIllegalArgumentError("API base URL is required.")
|
||||||
self.api_base_url = Mastodon.__protocolize(self.api_base_url)
|
self.api_base_url = Mastodon.__protocolize(self.api_base_url)
|
||||||
|
|
||||||
if not version_check_mode in ["created", "changed", "none"]:
|
if not version_check_mode in ["created", "changed", "none"]:
|
||||||
|
|
|
@ -5,7 +5,8 @@ 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
|
||||||
###
|
###
|
||||||
|
|
|
@ -61,4 +61,4 @@ _SCOPE_SETS = {
|
||||||
}
|
}
|
||||||
_VALID_SCOPES = ['read', 'write', 'follow', 'push', 'admin:read', 'admin:write'] + \
|
_VALID_SCOPES = ['read', 'write', 'follow', 'push', 'admin:read', 'admin:write'] + \
|
||||||
_SCOPE_SETS['read'] + _SCOPE_SETS['write'] + \
|
_SCOPE_SETS['read'] + _SCOPE_SETS['write'] + \
|
||||||
_SCOPE_SETS['admin:read'] + _SCOPE_SETS['admin:write']
|
_SCOPE_SETS['admin:read'] + _SCOPE_SETS['admin:write']
|
||||||
|
|
|
@ -5,7 +5,8 @@ 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
|
||||||
|
@ -49,4 +50,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,10 +22,11 @@ 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
|
||||||
###
|
###
|
||||||
class Mastodon():
|
class Mastodon():
|
||||||
def __datetime_to_epoch(self, date_time):
|
def __datetime_to_epoch(self, date_time):
|
||||||
"""
|
"""
|
||||||
Converts a python datetime to unix epoch, accounting for
|
Converts a python datetime to unix epoch, accounting for
|
||||||
|
@ -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.
|
||||||
|
@ -77,7 +77,7 @@ class Mastodon():
|
||||||
mark_delete.append(k)
|
mark_delete.append(k)
|
||||||
# Two step process because otherwise python gets very upset
|
# Two step process because otherwise python gets very upset
|
||||||
for k in mark_delete:
|
for k in mark_delete:
|
||||||
del json_object[k]
|
del json_object[k]
|
||||||
return json_object
|
return json_object
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -98,7 +98,7 @@ class Mastodon():
|
||||||
"""
|
"""
|
||||||
Converts json string numerals to native python bignums.
|
Converts json string numerals to native python bignums.
|
||||||
"""
|
"""
|
||||||
for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses',
|
for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses',
|
||||||
'day', 'last_read_id', 'value', 'frequency', 'rate', 'invited_by_account_id', 'count'):
|
'day', 'last_read_id', 'value', 'frequency', 'rate', 'invited_by_account_id', 'count'):
|
||||||
if (key in json_object and isinstance(json_object[key], six.text_type)):
|
if (key in json_object and isinstance(json_object[key], six.text_type)):
|
||||||
try:
|
try:
|
||||||
|
@ -131,14 +131,14 @@ class Mastodon():
|
||||||
isotime = isotime[:-2] + ":" + isotime[-2:]
|
isotime = isotime[:-2] + ":" + isotime[-2:]
|
||||||
return isotime
|
return isotime
|
||||||
|
|
||||||
def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, base_url_override=None,
|
def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, base_url_override=None,
|
||||||
do_ratelimiting=True, use_json=False, parse=True, return_response_object=False, skip_error_check=False, lang_override=None):
|
do_ratelimiting=True, use_json=False, parse=True, return_response_object=False, skip_error_check=False, lang_override=None):
|
||||||
"""
|
"""
|
||||||
Internal API request helper.
|
Internal API request helper.
|
||||||
"""
|
"""
|
||||||
response = None
|
response = None
|
||||||
remaining_wait = 0
|
remaining_wait = 0
|
||||||
|
|
||||||
# Add language to params if not None
|
# Add language to params if not None
|
||||||
lang = self.lang
|
lang = self.lang
|
||||||
if lang_override is not None:
|
if lang_override is not None:
|
||||||
|
@ -270,7 +270,7 @@ class Mastodon():
|
||||||
time.sleep(to_next)
|
time.sleep(to_next)
|
||||||
request_complete = False
|
request_complete = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not skip_error_check:
|
if not skip_error_check:
|
||||||
if response_object.status_code == 404:
|
if response_object.status_code == 404:
|
||||||
ex_type = MastodonNotFoundError
|
ex_type = MastodonNotFoundError
|
||||||
|
@ -665,4 +665,4 @@ class Mastodon():
|
||||||
return version_string.split("+")[1]
|
return version_string.split("+")[1]
|
||||||
except:
|
except:
|
||||||
# If this fails, assume that if there is a +, what is before that is the masto version (or that there is no +)
|
# If this fails, assume that if there is a +, what is before that is the masto version (or that there is no +)
|
||||||
return version_string.split("+")[0]
|
return version_string.split("+")[0]
|
||||||
|
|
|
@ -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
|
||||||
|
@ -107,4 +108,4 @@ class Mastodon(Internals):
|
||||||
account_ids = list(map(lambda x: self.__unpack_id(x), account_ids))
|
account_ids = list(map(lambda x: self.__unpack_id(x), account_ids))
|
||||||
|
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
self.__api_request('DELETE', f'/api/v1/lists/{id}/accounts', params)
|
self.__api_request('DELETE', f'/api/v1/lists/{id}/accounts', 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: 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
|
||||||
|
@ -16,7 +17,7 @@ class Mastodon(Internals):
|
||||||
Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in
|
Fetch notifications (mentions, favourites, reblogs, follows) for the logged-in
|
||||||
user. Pass `account_id` to get only notifications originating from the given account.
|
user. Pass `account_id` to get only notifications originating from the given account.
|
||||||
|
|
||||||
There are different types of notifications:
|
There are different types of notifications:
|
||||||
* `follow` - A user followed the logged in user
|
* `follow` - A user followed the logged in user
|
||||||
* `follow_request` - A user has requested to follow the logged in user (for locked accounts)
|
* `follow_request` - A user has requested to follow the logged in user (for locked accounts)
|
||||||
* `favourite` - A user favourited a post by the logged in user
|
* `favourite` - A user favourited a post by the logged in user
|
||||||
|
@ -29,7 +30,7 @@ class Mastodon(Internals):
|
||||||
* `admin.report` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received
|
* `admin.report` - For accounts with appropriate permissions (TODO: document which those are when adding the permission API): A new report has been received
|
||||||
Parameters `exclude_types` and `types` are array of these types, specifying them will in- or exclude the
|
Parameters `exclude_types` and `types` are array of these types, specifying them will in- or exclude the
|
||||||
types of notifications given. It is legal to give both parameters at the same tine, the result will then
|
types of notifications given. It is legal to give both parameters at the same tine, the result will then
|
||||||
be the intersection of the results of both filters. Specifying `mentions_only` is a deprecated way to set
|
be the intersection of the results of both filters. Specifying `mentions_only` is a deprecated way to set
|
||||||
`exclude_types` to all but mentions.
|
`exclude_types` to all but mentions.
|
||||||
|
|
||||||
Can be passed an `id` to fetch a single notification.
|
Can be passed an `id` to fetch a single notification.
|
||||||
|
|
|
@ -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
|
||||||
|
@ -56,4 +57,4 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
poll_params = locals()
|
poll_params = locals()
|
||||||
del poll_params["self"]
|
del poll_params["self"]
|
||||||
return poll_params
|
return poll_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: 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
|
||||||
|
@ -148,14 +149,14 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
|
push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
|
||||||
push_key_priv = push_key_pair.private_numbers().private_value
|
push_key_priv = push_key_pair.private_numbers().private_value
|
||||||
try:
|
try:
|
||||||
push_key_pub = push_key_pair.public_key().public_bytes(
|
push_key_pub = push_key_pair.public_key().public_bytes(
|
||||||
serialization.Encoding.X962,
|
serialization.Encoding.X962,
|
||||||
serialization.PublicFormat.UncompressedPoint,
|
serialization.PublicFormat.UncompressedPoint,
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
|
push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
|
||||||
|
|
||||||
push_shared_secret = os.urandom(16)
|
push_shared_secret = os.urandom(16)
|
||||||
|
|
||||||
priv_dict = {
|
priv_dict = {
|
||||||
|
|
|
@ -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
|
||||||
|
@ -131,4 +132,4 @@ class Mastodon(Internals):
|
||||||
Remove a domain block for the logged-in user.
|
Remove a domain block for the logged-in user.
|
||||||
"""
|
"""
|
||||||
params = self.__generate_params(locals())
|
params = self.__generate_params(locals())
|
||||||
self.__api_request('DELETE', '/api/v1/domain_blocks', params)
|
self.__api_request('DELETE', '/api/v1/domain_blocks', params)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -59,4 +60,4 @@ class Mastodon(Internals):
|
||||||
del params_initial['forward']
|
del params_initial['forward']
|
||||||
|
|
||||||
params = self.__generate_params(params_initial)
|
params = self.__generate_params(params_initial)
|
||||||
return self.__api_request('POST', '/api/v1/reports/', params)
|
return self.__api_request('POST', '/api/v1/reports/', params)
|
||||||
|
|
|
@ -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,7 +9,8 @@ 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
|
||||||
###
|
###
|
||||||
|
@ -244,19 +245,19 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
Returns a :ref:`status dict <status dict>` with the new status.
|
Returns a :ref:`status dict <status dict>` with the new status.
|
||||||
"""
|
"""
|
||||||
return self.__status_internal(
|
return self.__status_internal(
|
||||||
status,
|
status,
|
||||||
in_reply_to_id,
|
in_reply_to_id,
|
||||||
media_ids,
|
media_ids,
|
||||||
sensitive,
|
sensitive,
|
||||||
visibility,
|
visibility,
|
||||||
spoiler_text,
|
spoiler_text,
|
||||||
language,
|
language,
|
||||||
idempotency_key,
|
idempotency_key,
|
||||||
content_type,
|
content_type,
|
||||||
scheduled_at,
|
scheduled_at,
|
||||||
poll,
|
poll,
|
||||||
quote_id,
|
quote_id,
|
||||||
edit=None
|
edit=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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,13 +281,13 @@ 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)
|
||||||
def status_history(self, id):
|
def status_history(self, id):
|
||||||
|
@ -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.
|
||||||
|
|
||||||
Set `untag` to True if you want the reply to only go to the user you
|
Set `untag` to True if you want the reply to only go to the user you
|
||||||
|
|
|
@ -84,7 +84,7 @@ class StreamListener(object):
|
||||||
contains the content of the unknown event.
|
contains the content of the unknown event.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def handle_heartbeat(self):
|
def handle_heartbeat(self):
|
||||||
"""The server has sent us a keep-alive message. This callback may be
|
"""The server has sent us a keep-alive message. This callback may be
|
||||||
useful to carry out periodic housekeeping tasks, or just to confirm
|
useful to carry out periodic housekeeping tasks, or just to confirm
|
||||||
|
@ -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.
|
||||||
|
@ -226,21 +227,20 @@ class CallbackStreamListener(StreamListener):
|
||||||
for diagnostics.
|
for diagnostics.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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
|
||||||
|
@ -306,4 +306,4 @@ class CallbackStreamListener(StreamListener):
|
||||||
|
|
||||||
def on_unknown_event(self, name, unknown_event=None):
|
def on_unknown_event(self, name, unknown_event=None):
|
||||||
if self.unknown_event_handler is not None:
|
if self.unknown_event_handler is not None:
|
||||||
self.unknown_event_handler(name, unknown_event)
|
self.unknown_event_handler(name, unknown_event)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -14,7 +15,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
Alias for :ref:`trending_tags() <trending_tags()>`
|
Alias for :ref:`trending_tags() <trending_tags()>`
|
||||||
"""
|
"""
|
||||||
return self.trending_tags(limit=limit)
|
return self.trending_tags(limit=limit)
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG)
|
||||||
def trending_tags(self, limit=None, lang=None):
|
def trending_tags(self, limit=None, lang=None):
|
||||||
|
@ -27,7 +28,7 @@ class Mastodon(Internals):
|
||||||
Does not require authentication unless locked down by the administrator.
|
Does not require authentication unless locked down by the administrator.
|
||||||
|
|
||||||
Important versioning note: This endpoint does not exist for Mastodon versions
|
Important versioning note: This endpoint does not exist for Mastodon versions
|
||||||
between 2.8.0 (inclusive) and 3.0.0 (exclusive).
|
between 2.8.0 (inclusive) and 3.0.0 (exclusive).
|
||||||
|
|
||||||
Pass `lang` to override the global locale parameter, which may affect trend ordering.
|
Pass `lang` to override the global locale parameter, which may affect trend ordering.
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -91,7 +94,7 @@ class Mastodon():
|
||||||
not have one, 639-3 (three letter) language codes. This affects some error messages (those related to validation) and trends.
|
not have one, 639-3 (three letter) language codes. This affects some error messages (those related to validation) and trends.
|
||||||
"""
|
"""
|
||||||
self.lang = lang
|
self.lang = lang
|
||||||
|
|
||||||
def retrieve_mastodon_version(self):
|
def retrieve_mastodon_version(self):
|
||||||
"""
|
"""
|
||||||
Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly.
|
Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly.
|
||||||
|
@ -127,7 +130,7 @@ class Mastodon():
|
||||||
elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch:
|
elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_approx_server_time(self):
|
def get_approx_server_time(self):
|
||||||
"""
|
"""
|
||||||
Retrieve the approximate server time
|
Retrieve the approximate server time
|
||||||
|
|
|
@ -37,4 +37,4 @@ _DICT_VERSION_FAMILIAR_FOLLOWERS = max_version("3.5.0", _DICT_VERSION_ACCOUNT)
|
||||||
_DICT_VERSION_ADMIN_DOMAIN_BLOCK = "4.0.0"
|
_DICT_VERSION_ADMIN_DOMAIN_BLOCK = "4.0.0"
|
||||||
_DICT_VERSION_ADMIN_MEASURE = "3.5.0"
|
_DICT_VERSION_ADMIN_MEASURE = "3.5.0"
|
||||||
_DICT_VERSION_ADMIN_DIMENSION = "3.5.0"
|
_DICT_VERSION_ADMIN_DIMENSION = "3.5.0"
|
||||||
_DICT_VERSION_ADMIN_RETENTION = "3.5.0"
|
_DICT_VERSION_ADMIN_RETENTION = "3.5.0"
|
||||||
|
|
Ładowanie…
Reference in New Issue