kopia lustrzana https://github.com/halcy/Mastodon.py
refactor: use f-strings
rodzic
c796cf39b0
commit
325cc917d5
|
@ -66,7 +66,7 @@ class Mastodon(Internals):
|
||||||
response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False)
|
response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False)
|
||||||
temp_access_token = response['access_token']
|
temp_access_token = response['access_token']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonIllegalArgumentError('Invalid request during oauth phase: %s' % e)
|
raise MastodonIllegalArgumentError(f'Invalid request during oauth phase: {e}')
|
||||||
|
|
||||||
# Step 2: Use that to create a user
|
# Step 2: Use that to create a user
|
||||||
try:
|
try:
|
||||||
|
@ -74,7 +74,7 @@ class Mastodon(Internals):
|
||||||
if "error" in response:
|
if "error" in response:
|
||||||
if return_detailed_error:
|
if return_detailed_error:
|
||||||
return None, response
|
return None, response
|
||||||
raise MastodonIllegalArgumentError('Invalid request: %s' % 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)))
|
||||||
|
@ -88,7 +88,10 @@ class Mastodon(Internals):
|
||||||
received_scopes += _SCOPE_SETS[scope_set]
|
received_scopes += _SCOPE_SETS[scope_set]
|
||||||
|
|
||||||
if not set(scopes) <= set(received_scopes):
|
if not set(scopes) <= set(received_scopes):
|
||||||
raise MastodonAPIError('Granted scopes "' + " ".join(received_scopes) + '" do not contain all of the requested scopes "' + " ".join(scopes) + '".')
|
raise MastodonAPIError(
|
||||||
|
f'Granted scopes "{" ".join(received_scopes)}" '
|
||||||
|
f'do not contain all of the requested scopes "{" ".join(scopes)}".'
|
||||||
|
)
|
||||||
|
|
||||||
if to_file is not None:
|
if to_file is not None:
|
||||||
with open(to_file, 'w') as token_file:
|
with open(to_file, 'w') as token_file:
|
||||||
|
@ -124,8 +127,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`account dict <account dict>`.
|
Returns a :ref:`account dict <account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
||||||
def account_verify_credentials(self):
|
def account_verify_credentials(self):
|
||||||
|
@ -185,8 +187,7 @@ class Mastodon(Internals):
|
||||||
if not exclude_reblogs:
|
if not exclude_reblogs:
|
||||||
del params["exclude_reblogs"]
|
del params["exclude_reblogs"]
|
||||||
|
|
||||||
url = '/api/v1/accounts/{0}/statuses'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}/statuses', params)
|
||||||
return self.__api_request('GET', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
||||||
def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
|
@ -206,8 +207,7 @@ class Mastodon(Internals):
|
||||||
since_id = self.__unpack_id(since_id, dateconv=True)
|
since_id = self.__unpack_id(since_id, dateconv=True)
|
||||||
|
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/accounts/{0}/following'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}/following', params)
|
||||||
return self.__api_request('GET', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
||||||
def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
|
@ -227,8 +227,7 @@ class Mastodon(Internals):
|
||||||
since_id = self.__unpack_id(since_id, dateconv=True)
|
since_id = self.__unpack_id(since_id, dateconv=True)
|
||||||
|
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/accounts/{0}/followers'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}/followers', params)
|
||||||
return self.__api_request('GET', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_relationships(self, id):
|
def account_relationships(self, id):
|
||||||
|
@ -269,8 +268,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/accounts/{0}/lists'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}/lists', params)
|
||||||
return self.__api_request('GET', url, params)
|
|
||||||
|
|
||||||
@api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT)
|
@api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT)
|
||||||
def account_lookup(self, acct):
|
def account_lookup(self, acct):
|
||||||
|
@ -317,8 +315,7 @@ class Mastodon(Internals):
|
||||||
if params["reblogs"] is None:
|
if params["reblogs"] is None:
|
||||||
del params["reblogs"]
|
del params["reblogs"]
|
||||||
|
|
||||||
url = '/api/v1/accounts/{0}/follow'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/follow', params)
|
||||||
return self.__api_request('POST', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
||||||
def follows(self, uri):
|
def follows(self, uri):
|
||||||
|
@ -338,7 +335,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/accounts/{0}/unfollow'.format(str(id)))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/unfollow')
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_remove_from_followers(self, id):
|
def account_remove_from_followers(self, id):
|
||||||
|
@ -349,7 +346,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status.
|
Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/accounts/{0}/remove_from_followers'.format(str(id)))
|
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)
|
||||||
|
@ -360,8 +357,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}/block'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/block')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_unblock(self, id):
|
def account_unblock(self, id):
|
||||||
|
@ -371,8 +367,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}/unblock'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/unblock')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_mute(self, id, notifications=True, duration=None):
|
def account_mute(self, id, notifications=True, duration=None):
|
||||||
|
@ -387,8 +382,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/accounts/{0}/mute'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/mute', params)
|
||||||
return self.__api_request('POST', url, params)
|
|
||||||
|
|
||||||
@api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_unmute(self, id):
|
def account_unmute(self, id):
|
||||||
|
@ -398,8 +392,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}/unmute'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/unmute', params)
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT)
|
||||||
def account_update_credentials(self, display_name=None, note=None,
|
def account_update_credentials(self, display_name=None, note=None,
|
||||||
|
@ -436,10 +429,8 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
fields_attributes = []
|
fields_attributes = []
|
||||||
for idx, (field_name, field_value) in enumerate(fields):
|
for idx, (field_name, field_value) in enumerate(fields):
|
||||||
params_initial['fields_attributes[' +
|
params_initial[f'fields_attributes[{idx}][name]'] = field_name
|
||||||
str(idx) + '][name]'] = field_name
|
params_initial[f'fields_attributes[{idx}][value]'] = field_value
|
||||||
params_initial['fields_attributes[' +
|
|
||||||
str(idx) + '][value]'] = field_value
|
|
||||||
|
|
||||||
# Clean up params
|
# Clean up params
|
||||||
for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]:
|
for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]:
|
||||||
|
@ -464,8 +455,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}/pin'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/pin')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_unpin(self, id):
|
def account_unpin(self, id):
|
||||||
|
@ -475,8 +465,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/accounts/{0}/unpin'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/unpin')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def account_note_set(self, id, comment):
|
def account_note_set(self, id, comment):
|
||||||
|
@ -487,7 +476,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ["id"])
|
params = self.__generate_params(locals(), ["id"])
|
||||||
return self.__api_request('POST', '/api/v1/accounts/{0}/note'.format(str(id)), params)
|
return self.__api_request('POST', f'/api/v1/accounts/{id}/note', params)
|
||||||
|
|
||||||
@api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG)
|
@api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG)
|
||||||
def account_featured_tags(self, id):
|
def account_featured_tags(self, id):
|
||||||
|
@ -497,4 +486,4 @@ class Mastodon(Internals):
|
||||||
Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_).
|
Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_).
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/accounts/{0}/featured_tags'.format(str(id)))
|
return self.__api_request('GET', f'/api/v1/accounts/{id}/featured_tags')
|
||||||
|
|
|
@ -142,7 +142,7 @@ class Mastodon(Internals):
|
||||||
Returns that dict.
|
Returns that dict.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/admin/accounts/{0}'.format(id))
|
return self.__api_request('GET', f'/api/v1/admin/accounts/{id}')
|
||||||
|
|
||||||
@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_account_enable(self, id):
|
def admin_account_enable(self, id):
|
||||||
|
@ -152,7 +152,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>`.
|
Returns the updated :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/enable'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/enable')
|
||||||
|
|
||||||
@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_account_approve(self, id):
|
def admin_account_approve(self, id):
|
||||||
|
@ -162,7 +162,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>`.
|
Returns the updated :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/approve'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/approve')
|
||||||
|
|
||||||
@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_account_reject(self, id):
|
def admin_account_reject(self, id):
|
||||||
|
@ -172,7 +172,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>` for the account that is now gone.
|
Returns the updated :ref:`admin account dict <admin account dict>` for the account that is now gone.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/reject'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/reject')
|
||||||
|
|
||||||
@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_account_unsilence(self, id):
|
def admin_account_unsilence(self, id):
|
||||||
|
@ -182,7 +182,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>`.
|
Returns the updated :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsilence'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/unsilence')
|
||||||
|
|
||||||
@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_account_unsuspend(self, id):
|
def admin_account_unsuspend(self, id):
|
||||||
|
@ -192,7 +192,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>`.
|
Returns the updated :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsuspend'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/unsuspend')
|
||||||
|
|
||||||
@api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
@api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
||||||
def admin_account_delete(self, id):
|
def admin_account_delete(self, id):
|
||||||
|
@ -202,7 +202,7 @@ class Mastodon(Internals):
|
||||||
The deleted accounts :ref:`admin account dict <admin account dict>`.
|
The deleted accounts :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('DELETE', '/api/v1/admin/accounts/{0}'.format(id))
|
return self.__api_request('DELETE', f'/api/v1/admin/accounts/{id}')
|
||||||
|
|
||||||
@api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
@api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
|
||||||
def admin_account_unsensitive(self, id):
|
def admin_account_unsensitive(self, id):
|
||||||
|
@ -212,7 +212,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`admin account dict <admin account dict>`.
|
Returns the updated :ref:`admin account dict <admin account dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsensitive'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/accounts/{f}/unsensitive')
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", "2.9.1")
|
@api_version("2.9.1", "2.9.1", "2.9.1")
|
||||||
def admin_account_moderate(self, id, action=None, report_id=None, warning_preset_id=None, text=None, send_email_notification=True):
|
def admin_account_moderate(self, id, action=None, report_id=None, warning_preset_id=None, text=None, send_email_notification=True):
|
||||||
|
@ -248,8 +248,7 @@ class Mastodon(Internals):
|
||||||
|
|
||||||
params["type"] = action
|
params["type"] = action
|
||||||
|
|
||||||
self.__api_request(
|
self.__api_request('POST', f'/api/v1/admin/accounts/{id}/action', params)
|
||||||
'POST', '/api/v1/admin/accounts/{0}/action'.format(id), params)
|
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
||||||
def admin_reports(self, resolved=False, account_id=None, target_account_id=None, max_id=None, min_id=None, since_id=None, limit=None):
|
def admin_reports(self, resolved=False, account_id=None, target_account_id=None, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
|
@ -290,7 +289,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`report dict <report dict>`.
|
Returns a :ref:`report dict <report dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/admin/reports/{0}'.format(id))
|
return self.__api_request('GET', f'/api/v1/admin/reports/{id}')
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
||||||
def admin_report_assign(self, id):
|
def admin_report_assign(self, id):
|
||||||
|
@ -300,7 +299,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`report dict <report dict>`.
|
Returns the updated :ref:`report dict <report dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/reports/{0}/assign_to_self'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/reports/{id}/assign_to_self')
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
||||||
def admin_report_unassign(self, id):
|
def admin_report_unassign(self, id):
|
||||||
|
@ -310,7 +309,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`report dict <report dict>`.
|
Returns the updated :ref:`report dict <report dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/reports/{0}/unassign'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/reports/{id}/unassign')
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
||||||
def admin_report_reopen(self, id):
|
def admin_report_reopen(self, id):
|
||||||
|
@ -320,7 +319,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`report dict <report dict>`.
|
Returns the updated :ref:`report dict <report dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/reports/{0}/reopen'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/reports/{id}/reopen')
|
||||||
|
|
||||||
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
@api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
|
||||||
def admin_report_resolve(self, id):
|
def admin_report_resolve(self, id):
|
||||||
|
@ -330,7 +329,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`report dict <report dict>`.
|
Returns the updated :ref:`report dict <report dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id))
|
return self.__api_request('POST', f'/api/v1/admin/reports/{id}/resolve')
|
||||||
|
|
||||||
@api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG)
|
@api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG)
|
||||||
def admin_trending_tags(self, limit=None):
|
def admin_trending_tags(self, limit=None):
|
||||||
|
@ -376,7 +375,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
if id is not None:
|
if id is not None:
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(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)
|
||||||
|
@ -430,7 +429,7 @@ class Mastodon(Internals):
|
||||||
raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.")
|
raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.")
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ["id"])
|
params = self.__generate_params(locals(), ["id"])
|
||||||
return self.__api_request('PUT', '/api/v1/admin/domain_blocks/{0}'.format(id), params)
|
return self.__api_request('PUT', f'/api/v1/admin/domain_blocks/{id}', 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_delete_domain_block(self, id=None):
|
def admin_delete_domain_block(self, id=None):
|
||||||
|
@ -443,7 +442,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
if id is not None:
|
if id is not None:
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id))
|
self.__api_request('DELETE', f'/api/v1/admin/domain_blocks/{id}')
|
||||||
else:
|
else:
|
||||||
raise AttributeError("You must provide an id of an existing domain block to remove it.")
|
raise AttributeError("You must provide an id of an existing domain block to remove it.")
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,13 @@ class Mastodon(Internals):
|
||||||
if website is not None:
|
if website is not None:
|
||||||
request_data['website'] = website
|
request_data['website'] = website
|
||||||
if session:
|
if session:
|
||||||
ret = session.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
|
ret = session.post(f"{api_base_url}/api/v1/apps", data=request_data, timeout=request_timeout)
|
||||||
response = ret.json()
|
response = ret.json()
|
||||||
else:
|
else:
|
||||||
response = requests.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout)
|
response = requests.post(f"{api_base_url}/api/v1/apps", data=request_data, timeout=request_timeout)
|
||||||
response = response.json()
|
response = response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request: %s" % e)
|
raise MastodonNetworkError(f"Could not complete request: {e}")
|
||||||
|
|
||||||
if to_file is not None:
|
if to_file is not None:
|
||||||
with open(to_file, 'w') as secret_file:
|
with open(to_file, 'w') as secret_file:
|
||||||
|
@ -325,11 +325,11 @@ class Mastodon(Internals):
|
||||||
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:
|
||||||
if username is not None or password is not None:
|
if username is not None or password is not None:
|
||||||
raise MastodonIllegalArgumentError('Invalid user name, password, or redirect_uris: %s' % e)
|
raise MastodonIllegalArgumentError(f'Invalid user name, password, or redirect_uris: {e}')
|
||||||
elif code is not None:
|
elif code is not None:
|
||||||
raise MastodonIllegalArgumentError('Invalid access token or redirect_uris: %s' % e)
|
raise MastodonIllegalArgumentError(f'Invalid access token or redirect_uris: {e}')
|
||||||
else:
|
else:
|
||||||
raise MastodonIllegalArgumentError('Invalid request: %s' % e)
|
raise MastodonIllegalArgumentError(f'Invalid request: {e}')
|
||||||
|
|
||||||
received_scopes = response["scope"].split(" ")
|
received_scopes = response["scope"].split(" ")
|
||||||
for scope_set in _SCOPE_SETS.keys():
|
for scope_set in _SCOPE_SETS.keys():
|
||||||
|
|
|
@ -39,5 +39,4 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`conversation dict <conversation dict>`.
|
Returns the updated :ref:`conversation dict <conversation dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/conversations/{0}/read'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/conversations/{id}/read')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`filter dict <filter dict>`.
|
Returns a :ref:`filter dict <filter dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/filters/{0}'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/filters/{id}')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("2.4.3", "2.4.3", _DICT_VERSION_FILTER)
|
@api_version("2.4.3", "2.4.3", _DICT_VERSION_FILTER)
|
||||||
def filters_apply(self, objects, filters, context):
|
def filters_apply(self, objects, filters, context):
|
||||||
|
@ -106,8 +105,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/filters/{0}'.format(str(id))
|
return self.__api_request('PUT', f'/api/v1/filters/{id}', params)
|
||||||
return self.__api_request('PUT', url, params)
|
|
||||||
|
|
||||||
@api_version("2.4.3", "2.4.3", "2.4.3")
|
@api_version("2.4.3", "2.4.3", "2.4.3")
|
||||||
def filter_delete(self, id):
|
def filter_delete(self, id):
|
||||||
|
@ -115,5 +113,4 @@ class Mastodon(Internals):
|
||||||
Deletes the filter with the given `id`.
|
Deletes the filter with the given `id`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/filters/{0}'.format(str(id))
|
self.__api_request('DELETE', f'/api/v1/filters/{id}')
|
||||||
self.__api_request('DELETE', url)
|
|
||||||
|
|
|
@ -47,6 +47,4 @@ class Mastodon(Internals):
|
||||||
Deletes one of the logged-in user's featured hashtags.
|
Deletes one of the logged-in user's featured hashtags.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/featured_tags/{0}'.format(str(id))
|
self.__api_request('DELETE', f'/api/v1/featured_tags/{id}')
|
||||||
self.__api_request('DELETE', url)
|
|
||||||
|
|
||||||
|
|
|
@ -156,8 +156,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
|
|
||||||
url = '/api/v1/announcements/{0}/dismiss'.format(str(id))
|
self.__api_request('POST', f'/api/v1/announcements/{id}/dismiss')
|
||||||
self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("3.1.0", "3.1.0", "3.1.0")
|
@api_version("3.1.0", "3.1.0", "3.1.0")
|
||||||
def announcement_reaction_create(self, id, reaction):
|
def announcement_reaction_create(self, id, reaction):
|
||||||
|
@ -171,9 +170,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
|
|
||||||
url = '/api/v1/announcements/{0}/reactions/{1}'.format(
|
self.__api_request('PUT', f'/api/v1/announcements/{id}/reactions/{reaction}')
|
||||||
str(id), reaction)
|
|
||||||
self.__api_request('PUT', url)
|
|
||||||
|
|
||||||
@api_version("3.1.0", "3.1.0", "3.1.0")
|
@api_version("3.1.0", "3.1.0", "3.1.0")
|
||||||
def announcement_reaction_delete(self, id, reaction):
|
def announcement_reaction_delete(self, id, reaction):
|
||||||
|
@ -184,6 +181,4 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
|
|
||||||
url = '/api/v1/announcements/{0}/reactions/{1}'.format(
|
self.__api_request('DELETE', f'/api/v1/announcements/{id}/reactions/{reaction}')
|
||||||
str(id), reaction)
|
|
||||||
self.__api_request('DELETE', url)
|
|
||||||
|
|
|
@ -182,11 +182,10 @@ class Mastodon():
|
||||||
base_url = base_url_override
|
base_url = base_url_override
|
||||||
|
|
||||||
if self.debug_requests:
|
if self.debug_requests:
|
||||||
print('Mastodon: Request to endpoint "' + base_url +
|
print(f'Mastodon: Request to endpoint "{base_url}{endpoint}" using method "{method}".')
|
||||||
endpoint + '" using method "' + method + '".')
|
print(f'Parameters: {params}')
|
||||||
print('Parameters: ' + str(params))
|
print(f'Headers: {headers}')
|
||||||
print('Headers: ' + str(headers))
|
print(f'Files: {files}')
|
||||||
print('Files: ' + str(files))
|
|
||||||
|
|
||||||
# Make request
|
# Make request
|
||||||
request_complete = False
|
request_complete = False
|
||||||
|
@ -205,7 +204,7 @@ class Mastodon():
|
||||||
|
|
||||||
response_object = self.session.request(method, base_url + endpoint, **kwargs)
|
response_object = self.session.request(method, base_url + endpoint, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request: %s" % e)
|
raise MastodonNetworkError(f"Could not complete request: {e}")
|
||||||
|
|
||||||
if response_object is None:
|
if response_object is None:
|
||||||
raise MastodonIllegalArgumentError("Illegal request.")
|
raise MastodonIllegalArgumentError("Illegal request.")
|
||||||
|
@ -219,8 +218,7 @@ class Mastodon():
|
||||||
|
|
||||||
# For gotosocial, we need an int representation, but for non-ints this would crash
|
# For gotosocial, we need an int representation, but for non-ints this would crash
|
||||||
try:
|
try:
|
||||||
ratelimit_intrep = str(
|
ratelimit_intrep = str(int(response_object.headers['X-RateLimit-Reset']))
|
||||||
int(response_object.headers['X-RateLimit-Reset']))
|
|
||||||
except:
|
except:
|
||||||
ratelimit_intrep = None
|
ratelimit_intrep = None
|
||||||
|
|
||||||
|
@ -240,13 +238,13 @@ class Mastodon():
|
||||||
self.ratelimit_reset += server_time_diff
|
self.ratelimit_reset += server_time_diff
|
||||||
self.ratelimit_lastcall = time.time()
|
self.ratelimit_lastcall = time.time()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
|
raise MastodonRatelimitError(f"Rate limit time calculations failed: {e}")
|
||||||
|
|
||||||
# Handle response
|
# Handle response
|
||||||
if self.debug_requests:
|
if self.debug_requests:
|
||||||
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')
|
print(f'Mastodon: Response received with code {response_object.status_code}.')
|
||||||
print('response headers: ' + str(response_object.headers))
|
print(f'response headers: {response_object.headers}')
|
||||||
print('Response text content: ' + str(response_object.text))
|
print(f'Response text content: {response_object.text}')
|
||||||
|
|
||||||
if not response_object.ok:
|
if not response_object.ok:
|
||||||
try:
|
try:
|
||||||
|
@ -306,9 +304,9 @@ class Mastodon():
|
||||||
response = response_object.json(object_hook=self.__json_hooks)
|
response = response_object.json(object_hook=self.__json_hooks)
|
||||||
except:
|
except:
|
||||||
raise MastodonAPIError(
|
raise MastodonAPIError(
|
||||||
"Could not parse response as JSON, response code was %s, "
|
f"Could not parse response as JSON, response code was {response_object.status_code}, "
|
||||||
"bad json content was '%s'" % (response_object.status_code,
|
f"bad json content was {response_object.content!r}."
|
||||||
response_object.content))
|
)
|
||||||
else:
|
else:
|
||||||
response = response_object.content
|
response = response_object.content
|
||||||
|
|
||||||
|
@ -413,8 +411,8 @@ class Mastodon():
|
||||||
url = "http://" + parse.netloc
|
url = "http://" + parse.netloc
|
||||||
else:
|
else:
|
||||||
raise MastodonAPIError(
|
raise MastodonAPIError(
|
||||||
"Could not parse streaming api location returned from server: {}.".format(
|
f"Could not parse streaming api location returned from server: {instance['urls']['streaming_api']}."
|
||||||
instance["urls"]["streaming_api"]))
|
)
|
||||||
else:
|
else:
|
||||||
url = self.api_base_url
|
url = self.api_base_url
|
||||||
return url
|
return url
|
||||||
|
@ -436,16 +434,14 @@ class Mastodon():
|
||||||
|
|
||||||
# Connect function (called and then potentially passed to async handler)
|
# Connect function (called and then potentially passed to async handler)
|
||||||
def connect_func():
|
def connect_func():
|
||||||
headers = {"Authorization": "Bearer " +
|
headers = {"Authorization": "Bearer " + self.access_token} if self.access_token else {}
|
||||||
self.access_token} if self.access_token else {}
|
|
||||||
if self.user_agent:
|
if self.user_agent:
|
||||||
headers['User-Agent'] = self.user_agent
|
headers['User-Agent'] = self.user_agent
|
||||||
connection = self.session.get(url + endpoint, headers=headers, data=params, stream=True,
|
connection = self.session.get(url + endpoint, headers=headers, data=params, stream=True,
|
||||||
timeout=(self.request_timeout, timeout))
|
timeout=(self.request_timeout, timeout))
|
||||||
|
|
||||||
if connection.status_code != 200:
|
if connection.status_code != 200:
|
||||||
raise MastodonNetworkError(
|
raise MastodonNetworkError(f"Could not connect to streaming server: {connection.reason}")
|
||||||
"Could not connect to streaming server: %s" % connection.reason)
|
|
||||||
return connection
|
return connection
|
||||||
connection = None
|
connection = None
|
||||||
|
|
||||||
|
@ -638,7 +634,7 @@ class Mastodon():
|
||||||
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
random_suffix = uuid.uuid4().hex
|
random_suffix = uuid.uuid4().hex
|
||||||
file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension(mime_type)
|
file_name = f"mastodonpyupload_{time.time()}_{random_suffix}{mimetypes.guess_extension(mime_type)}"
|
||||||
return (file_name, media_file, mime_type)
|
return (file_name, media_file, mime_type)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`list dict <list dict>`.
|
Returns a :ref:`list dict <list dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/lists/{0}'.format(id))
|
return self.__api_request('GET', f'/api/v1/lists/{id}')
|
||||||
|
|
||||||
@api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
@api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT)
|
||||||
def list_accounts(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
def list_accounts(self, id, max_id=None, min_id=None, since_id=None, limit=None):
|
||||||
|
@ -47,7 +47,7 @@ class Mastodon(Internals):
|
||||||
since_id = self.__unpack_id(since_id, dateconv=True)
|
since_id = self.__unpack_id(since_id, dateconv=True)
|
||||||
|
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
return self.__api_request('GET', '/api/v1/lists/{0}/accounts'.format(id))
|
return self.__api_request('GET', f'/api/v1/lists/{id}/accounts')
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Lists
|
# Writing data: Lists
|
||||||
|
@ -71,7 +71,7 @@ class Mastodon(Internals):
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
return self.__api_request('PUT', '/api/v1/lists/{0}'.format(id), params)
|
return self.__api_request('PUT', f'/api/v1/lists/{id}', params)
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", "2.1.0")
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
||||||
def list_delete(self, id):
|
def list_delete(self, id):
|
||||||
|
@ -79,7 +79,7 @@ class Mastodon(Internals):
|
||||||
Delete a list.
|
Delete a list.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id))
|
self.__api_request('DELETE', f'/api/v1/lists/{id}')
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", "2.1.0")
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
||||||
def list_accounts_add(self, id, account_ids):
|
def list_accounts_add(self, id, account_ids):
|
||||||
|
@ -93,8 +93,7 @@ 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(
|
self.__api_request('POST', f'/api/v1/lists/{id}/accounts', params)
|
||||||
'POST', '/api/v1/lists/{0}/accounts'.format(id), params)
|
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", "2.1.0")
|
@api_version("2.1.0", "2.1.0", "2.1.0")
|
||||||
def list_accounts_delete(self, id, account_ids):
|
def list_accounts_delete(self, id, account_ids):
|
||||||
|
@ -108,5 +107,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(
|
self.__api_request('DELETE', f'/api/v1/lists/{id}/accounts', params)
|
||||||
'DELETE', '/api/v1/lists/{0}/accounts'.format(id), params)
|
|
|
@ -19,7 +19,7 @@ class Mastodon(Internals):
|
||||||
to the logged-in user.
|
to the logged-in user.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', '/api/v1/media/{0}'.format(str(id)))
|
return self.__api_request('GET', f'/api/v1/media/{id}')
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Media
|
# Writing data: Media
|
||||||
|
@ -57,7 +57,7 @@ class Mastodon(Internals):
|
||||||
media_file, mime_type, file_name)}
|
media_file, mime_type, file_name)}
|
||||||
|
|
||||||
if focus is not None:
|
if focus is not None:
|
||||||
focus = str(focus[0]) + "," + str(focus[1])
|
focus = f"{focus[0]},{focus[1]}"
|
||||||
|
|
||||||
if thumbnail is not None:
|
if thumbnail is not None:
|
||||||
if not self.verify_minimum_version("3.2.0", cached=True):
|
if not self.verify_minimum_version("3.2.0", cached=True):
|
||||||
|
@ -99,7 +99,7 @@ class Mastodon(Internals):
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
|
|
||||||
if focus is not None:
|
if focus is not None:
|
||||||
focus = str(focus[0]) + "," + str(focus[1])
|
focus = f"{focus[0]},{focus[1]}"
|
||||||
|
|
||||||
params = self.__generate_params(
|
params = self.__generate_params(
|
||||||
locals(), ['id', 'thumbnail', 'thumbnail_mime_type'])
|
locals(), ['id', 'thumbnail', 'thumbnail_mime_type'])
|
||||||
|
@ -109,6 +109,6 @@ class Mastodon(Internals):
|
||||||
raise MastodonVersionError('Thumbnail requires version > 3.2.0')
|
raise MastodonVersionError('Thumbnail requires version > 3.2.0')
|
||||||
files = {"thumbnail": self.__load_media_file(
|
files = {"thumbnail": self.__load_media_file(
|
||||||
thumbnail, thumbnail_mime_type)}
|
thumbnail, thumbnail_mime_type)}
|
||||||
return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params, files=files)
|
return self.__api_request('PUT', f'/api/v1/media/{id}', params, files=files)
|
||||||
else:
|
else:
|
||||||
return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params)
|
return self.__api_request('PUT', f'/api/v1/media/{id}', params)
|
||||||
|
|
|
@ -64,8 +64,7 @@ class Mastodon(Internals):
|
||||||
return self.__api_request('GET', '/api/v1/notifications', params)
|
return self.__api_request('GET', '/api/v1/notifications', params)
|
||||||
else:
|
else:
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/notifications/{0}'.format(str(id))
|
return self.__api_request('GET', f"/api/v1/notifications/{id}")
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Notifications
|
# Writing data: Notifications
|
||||||
|
@ -85,8 +84,7 @@ class Mastodon(Internals):
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
|
|
||||||
if self.verify_minimum_version("2.9.2", cached=True):
|
if self.verify_minimum_version("2.9.2", cached=True):
|
||||||
url = '/api/v1/notifications/{0}/dismiss'.format(str(id))
|
self.__api_request('POST', f'/api/v1/notifications/{id}/dismiss')
|
||||||
self.__api_request('POST', url)
|
|
||||||
else:
|
else:
|
||||||
params = self.__generate_params(locals())
|
params = self.__generate_params(locals())
|
||||||
self.__api_request('POST', '/api/v1/notifications/dismiss', params)
|
self.__api_request('POST', '/api/v1/notifications/dismiss', params)
|
||||||
|
|
|
@ -17,8 +17,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`poll dict <poll dict>`.
|
Returns a :ref:`poll dict <poll dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/polls/{0}'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/polls/{id}')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Polls
|
# Writing data: Polls
|
||||||
|
@ -44,8 +43,7 @@ class Mastodon(Internals):
|
||||||
choices = [choices]
|
choices = [choices]
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
|
|
||||||
url = '/api/v1/polls/{0}/votes'.format(id)
|
self.__api_request('POST', f'/api/v1/polls/{id}/votes', params)
|
||||||
self.__api_request('POST', url, params)
|
|
||||||
|
|
||||||
def make_poll(self, options, expires_in, multiple=False, hide_totals=False):
|
def make_poll(self, options, expires_in, multiple=False, hide_totals=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -102,8 +102,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
|
Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/follow_requests/{0}/authorize'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/follow_requests/{id}/authorize')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP)
|
@api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP)
|
||||||
def follow_request_reject(self, id):
|
def follow_request_reject(self, id):
|
||||||
|
@ -113,8 +112,7 @@ class Mastodon(Internals):
|
||||||
Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
|
Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/follow_requests/{0}/reject'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/follow_requests/{id}/reject')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Domain blocks
|
# Writing data: Domain blocks
|
||||||
|
|
|
@ -23,8 +23,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>`.
|
Returns a :ref:`status dict <status dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/statuses/{id}')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD)
|
@api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD)
|
||||||
def status_card(self, id):
|
def status_card(self, id):
|
||||||
|
@ -45,8 +44,7 @@ class Mastodon(Internals):
|
||||||
return self.status(id).card
|
return self.status(id).card
|
||||||
else:
|
else:
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/card'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/statuses/{id}/card')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT)
|
@api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT)
|
||||||
def status_context(self, id):
|
def status_context(self, id):
|
||||||
|
@ -58,8 +56,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`context dict <context dict>`.
|
Returns a :ref:`context dict <context dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/context'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/statuses/{id}/context')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
||||||
def status_reblogged_by(self, id):
|
def status_reblogged_by(self, id):
|
||||||
|
@ -71,8 +68,7 @@ class Mastodon(Internals):
|
||||||
Returns a list of :ref:`account dicts <account dicts>`.
|
Returns a list of :ref:`account dicts <account dicts>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/statuses/{id}/reblogged_by')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
@api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
|
||||||
def status_favourited_by(self, id):
|
def status_favourited_by(self, id):
|
||||||
|
@ -84,8 +80,7 @@ class Mastodon(Internals):
|
||||||
Returns a list of :ref:`account dicts <account dicts>`.
|
Returns a list of :ref:`account dicts <account dicts>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/favourited_by'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/statuses/{id}/favourited_by')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Reading data: Scheduled statuses
|
# Reading data: Scheduled statuses
|
||||||
|
@ -107,8 +102,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`scheduled status dict <scheduled status dict>`.
|
Returns a :ref:`scheduled status dict <scheduled status dict>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/scheduled_statuses/{0}'.format(str(id))
|
return self.__api_request('GET', f'/api/v1/scheduled_statuses/{id}')
|
||||||
return self.__api_request('GET', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Statuses
|
# Writing data: Statuses
|
||||||
|
@ -150,7 +144,7 @@ class Mastodon(Internals):
|
||||||
else:
|
else:
|
||||||
params_initial['visibility'] = params_initial['visibility'].lower()
|
params_initial['visibility'] = params_initial['visibility'].lower()
|
||||||
if params_initial['visibility'] not in valid_visibilities:
|
if params_initial['visibility'] not in valid_visibilities:
|
||||||
raise ValueError('Invalid visibility value! Acceptable values are %s' % valid_visibilities)
|
raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}')
|
||||||
|
|
||||||
if params_initial['language'] is None:
|
if params_initial['language'] is None:
|
||||||
del params_initial['language']
|
del params_initial['language']
|
||||||
|
@ -170,7 +164,7 @@ class Mastodon(Internals):
|
||||||
for media_id in media_ids:
|
for media_id in media_ids:
|
||||||
media_ids_proper.append(self.__unpack_id(media_id))
|
media_ids_proper.append(self.__unpack_id(media_id))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonIllegalArgumentError("Invalid media dict: %s" % e)
|
raise MastodonIllegalArgumentError(f"Invalid media dict: {e}")
|
||||||
|
|
||||||
params_initial["media_ids"] = media_ids_proper
|
params_initial["media_ids"] = media_ids_proper
|
||||||
|
|
||||||
|
@ -187,7 +181,7 @@ class Mastodon(Internals):
|
||||||
return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json)
|
return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json)
|
||||||
else:
|
else:
|
||||||
# Edit
|
# Edit
|
||||||
return self.__api_request('PUT', '/api/v1/statuses/{0}'.format(str(self.__unpack_id(edit))), params, headers=headers, use_json=use_json)
|
return self.__api_request('PUT', f'/api/v1/statuses/{self.__unpack_id(edit)}', params, headers=headers, use_json=use_json)
|
||||||
|
|
||||||
@api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
|
||||||
def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
def status_post(self, status, in_reply_to_id=None, media_ids=None,
|
||||||
|
@ -303,7 +297,7 @@ class Mastodon(Internals):
|
||||||
will have three, and so on.
|
will have three, and so on.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', "/api/v1/statuses/{0}/history".format(str(id)))
|
return self.__api_request('GET', f"/api/v1/statuses/{id}/history")
|
||||||
|
|
||||||
def status_source(self, id):
|
def status_source(self, id):
|
||||||
"""
|
"""
|
||||||
|
@ -314,7 +308,7 @@ class Mastodon(Internals):
|
||||||
instead.
|
instead.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__api_request('GET', "/api/v1/statuses/{0}/source".format(str(id)))
|
return self.__api_request('GET', f"/api/v1/statuses/{id}/source")
|
||||||
|
|
||||||
@api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
|
||||||
def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None,
|
def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None,
|
||||||
|
@ -372,8 +366,7 @@ class Mastodon(Internals):
|
||||||
"delete and redraft" functionality)
|
"delete and redraft" functionality)
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}'.format(str(id))
|
return self.__api_request('DELETE', f'/api/v1/statuses/{id}')
|
||||||
return self.__api_request('DELETE', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_reblog(self, id, visibility=None):
|
def status_reblog(self, id, visibility=None):
|
||||||
|
@ -390,12 +383,10 @@ class Mastodon(Internals):
|
||||||
if 'visibility' in params:
|
if 'visibility' in params:
|
||||||
params['visibility'] = params['visibility'].lower()
|
params['visibility'] = params['visibility'].lower()
|
||||||
if params['visibility'] not in valid_visibilities:
|
if params['visibility'] not in valid_visibilities:
|
||||||
raise ValueError('Invalid visibility value! Acceptable '
|
raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}')
|
||||||
'values are %s' % valid_visibilities)
|
|
||||||
|
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/reblog'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/reblog', params)
|
||||||
return self.__api_request('POST', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_unreblog(self, id):
|
def status_unreblog(self, id):
|
||||||
|
@ -405,8 +396,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the status that used to be reblogged.
|
Returns a :ref:`status dict <status dict>` with the status that used to be reblogged.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/unreblog'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/unreblog')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_favourite(self, id):
|
def status_favourite(self, id):
|
||||||
|
@ -416,8 +406,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the favourited status.
|
Returns a :ref:`status dict <status dict>` with the favourited status.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/favourite'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/favourite')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_unfavourite(self, id):
|
def status_unfavourite(self, id):
|
||||||
|
@ -427,8 +416,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the un-favourited status.
|
Returns a :ref:`status dict <status dict>` with the un-favourited status.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/unfavourite'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/unfavourite')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_mute(self, id):
|
def status_mute(self, id):
|
||||||
|
@ -438,8 +426,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the now muted status
|
Returns a :ref:`status dict <status dict>` with the now muted status
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/mute'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/mute')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
|
@api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
|
||||||
def status_unmute(self, id):
|
def status_unmute(self, id):
|
||||||
|
@ -449,8 +436,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the status that used to be muted.
|
Returns a :ref:`status dict <status dict>` with the status that used to be muted.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/unmute'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/unmute')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
||||||
def status_pin(self, id):
|
def status_pin(self, id):
|
||||||
|
@ -460,8 +446,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the now pinned status
|
Returns a :ref:`status dict <status dict>` with the now pinned status
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/pin'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/pin')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
||||||
def status_unpin(self, id):
|
def status_unpin(self, id):
|
||||||
|
@ -471,8 +456,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the status that used to be pinned.
|
Returns a :ref:`status dict <status dict>` with the status that used to be pinned.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/unpin'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/unpin')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
|
@api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
|
||||||
def status_bookmark(self, id):
|
def status_bookmark(self, id):
|
||||||
|
@ -482,8 +466,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the now bookmarked status
|
Returns a :ref:`status dict <status dict>` with the now bookmarked status
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/bookmark'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/bookmark')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
@api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
|
@api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
|
||||||
def status_unbookmark(self, id):
|
def status_unbookmark(self, id):
|
||||||
|
@ -493,8 +476,7 @@ class Mastodon(Internals):
|
||||||
Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked.
|
Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/statuses/{0}/unbookmark'.format(str(id))
|
return self.__api_request('POST', f'/api/v1/statuses/{id}/unbookmark')
|
||||||
return self.__api_request('POST', url)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Writing data: Scheduled statuses
|
# Writing data: Scheduled statuses
|
||||||
|
@ -511,8 +493,7 @@ class Mastodon(Internals):
|
||||||
scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
|
scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
params = self.__generate_params(locals(), ['id'])
|
params = self.__generate_params(locals(), ['id'])
|
||||||
url = '/api/v1/scheduled_statuses/{0}'.format(str(id))
|
return self.__api_request('PUT', f'/api/v1/scheduled_statuses/{id}', params)
|
||||||
return self.__api_request('PUT', url, params)
|
|
||||||
|
|
||||||
@api_version("2.7.0", "2.7.0", "2.7.0")
|
@api_version("2.7.0", "2.7.0", "2.7.0")
|
||||||
def scheduled_status_delete(self, id):
|
def scheduled_status_delete(self, id):
|
||||||
|
@ -520,5 +501,4 @@ class Mastodon(Internals):
|
||||||
Deletes a scheduled status.
|
Deletes a scheduled status.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
url = '/api/v1/scheduled_statuses/{0}'.format(str(id))
|
self.__api_request('DELETE', f'/api/v1/scheduled_statuses/{id}')
|
||||||
self.__api_request('DELETE', url)
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Mastodon(Internals):
|
||||||
base = '/api/v1/streaming/hashtag'
|
base = '/api/v1/streaming/hashtag'
|
||||||
if local:
|
if local:
|
||||||
base += '/local'
|
base += '/local'
|
||||||
return self.__stream("{}?tag={}".format(base, tag), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
|
return self.__stream(f"{base}?tag={tag}", listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
|
||||||
|
|
||||||
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
@api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
|
||||||
def stream_list(self, id, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
|
def stream_list(self, id, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
|
||||||
|
@ -55,7 +55,7 @@ class Mastodon(Internals):
|
||||||
list.
|
list.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.__stream("/api/v1/streaming/list?list={}".format(id), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
|
return self.__stream(f"/api/v1/streaming/list?list={id}", listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
|
||||||
|
|
||||||
@api_version("2.6.0", "2.6.0", _DICT_VERSION_STATUS)
|
@api_version("2.6.0", "2.6.0", _DICT_VERSION_STATUS)
|
||||||
def stream_direct(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
|
def stream_direct(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
|
||||||
|
|
|
@ -28,5 +28,4 @@ class Mastodon(Internals):
|
||||||
Remove the user with the given `account_id` from the follow suggestions.
|
Remove the user with the given `account_id` from the follow suggestions.
|
||||||
"""
|
"""
|
||||||
account_id = self.__unpack_id(account_id)
|
account_id = self.__unpack_id(account_id)
|
||||||
url = '/api/v1/suggestions/{0}'.format(str(account_id))
|
self.__api_request('DELETE', f'/api/v1/suggestions/{account_id}')
|
||||||
self.__api_request('DELETE', url)
|
|
||||||
|
|
|
@ -50,8 +50,7 @@ class Mastodon(Internals):
|
||||||
params_initial['local'] = True
|
params_initial['local'] = True
|
||||||
|
|
||||||
params = self.__generate_params(params_initial, ['timeline'])
|
params = self.__generate_params(params_initial, ['timeline'])
|
||||||
url = '/api/v1/timelines/{0}'.format(timeline)
|
return self.__api_request('GET', f'/api/v1/timelines/{timeline}', params)
|
||||||
return self.__api_request('GET', url, params)
|
|
||||||
|
|
||||||
@api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
|
@api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
|
||||||
def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
|
def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
|
||||||
|
@ -91,7 +90,7 @@ class Mastodon(Internals):
|
||||||
if hashtag.startswith("#"):
|
if hashtag.startswith("#"):
|
||||||
raise MastodonIllegalArgumentError(
|
raise MastodonIllegalArgumentError(
|
||||||
"Hashtag parameter should omit leading #")
|
"Hashtag parameter should omit leading #")
|
||||||
return self.timeline('tag/{0}'.format(hashtag), 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'tag/{hashtag}', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
|
||||||
|
|
||||||
@api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS)
|
@api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS)
|
||||||
def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
|
def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
|
||||||
|
@ -101,5 +100,5 @@ class Mastodon(Internals):
|
||||||
Returns a list of :ref:`status dicts <status dicts>`.
|
Returns a list of :ref:`status dicts <status dicts>`.
|
||||||
"""
|
"""
|
||||||
id = self.__unpack_id(id)
|
id = self.__unpack_id(id)
|
||||||
return self.timeline('list/{0}'.format(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)
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,13 @@ def api_version(created_ver, last_changed_ver, return_value_ver):
|
||||||
version = max_version(last_changed_ver, return_value_ver)
|
version = max_version(last_changed_ver, return_value_ver)
|
||||||
major, minor, patch = parse_version_string(version)
|
major, minor, patch = parse_version_string(version)
|
||||||
if major > self.mastodon_major:
|
if major > self.mastodon_major:
|
||||||
raise MastodonVersionError("Version check failed (Need version " + version + ")")
|
raise MastodonVersionError(f"Version check failed (Need version {version})")
|
||||||
elif major == self.mastodon_major and minor > self.mastodon_minor:
|
elif major == self.mastodon_major and minor > self.mastodon_minor:
|
||||||
raise MastodonVersionError("Version check failed (Need version " + version + ")")
|
raise MastodonVersionError(f"Version check failed (Need version {version})")
|
||||||
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:
|
||||||
raise MastodonVersionError("Version check failed (Need version " + version + ", patch is " + str(self.mastodon_patch) + ")")
|
raise MastodonVersionError(f"Version check failed (Need version {version}, patch is {self.mastodon_patch})")
|
||||||
return function(self, *args, **kwargs)
|
return function(self, *args, **kwargs)
|
||||||
function.__doc__ = function.__doc__ + "\n\n *Added: Mastodon v" + \
|
function.__doc__ += f"\n\n *Added: Mastodon v{created_ver}, last changed: Mastodon v{last_changed_ver}*"
|
||||||
created_ver + ", last changed: Mastodon v" + last_changed_ver + "*"
|
|
||||||
return decorate(function, wrapper)
|
return decorate(function, wrapper)
|
||||||
return api_min_version_decorator
|
return api_min_version_decorator
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ class AttribAccessDict(dict):
|
||||||
if attr in self:
|
if attr in self:
|
||||||
return self[attr]
|
return self[attr]
|
||||||
else:
|
else:
|
||||||
raise AttributeError("Attribute not found: " + str(attr))
|
raise AttributeError(f"Attribute not found: {attr}")
|
||||||
|
|
||||||
def __setattr__(self, attr, val):
|
def __setattr__(self, attr, val):
|
||||||
if attr in self:
|
if attr in self:
|
||||||
|
@ -76,7 +75,7 @@ class AttribAccessList(list):
|
||||||
if attr in self:
|
if attr in self:
|
||||||
return self[attr]
|
return self[attr]
|
||||||
else:
|
else:
|
||||||
raise AttributeError("Attribute not found: " + str(attr))
|
raise AttributeError(f"Attribute not found: {attr}")
|
||||||
|
|
||||||
def __setattr__(self, attr, val):
|
def __setattr__(self, attr, val):
|
||||||
if attr in self:
|
if attr in self:
|
||||||
|
|
|
@ -64,7 +64,7 @@ def test_app_account_create():
|
||||||
test_app[1],
|
test_app[1],
|
||||||
api_base_url="http://localhost:3000/"
|
api_base_url="http://localhost:3000/"
|
||||||
)
|
)
|
||||||
test_token = test_app_api.create_account("coolguy" + suffix, "swordfish", "email@localhost" + suffix, agreement=True)
|
test_token = test_app_api.create_account(f"coolguy{suffix}", "swordfish", f"email@localhost{suffix}", agreement=True)
|
||||||
assert test_token
|
assert test_token
|
||||||
|
|
||||||
# We can also test resending (marginally)
|
# We can also test resending (marginally)
|
||||||
|
|
|
@ -16,7 +16,7 @@ UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp"
|
||||||
def many_statuses(api, n=10, suffix=''):
|
def many_statuses(api, n=10, suffix=''):
|
||||||
statuses = list()
|
statuses = list()
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
status = api.status_post("Toot number {}!{}".format(i, suffix))
|
status = api.status_post(f"Toot number {i}!{suffix}")
|
||||||
statuses.append(status)
|
statuses.append(status)
|
||||||
yield statuses
|
yield statuses
|
||||||
for status in statuses:
|
for status in statuses:
|
||||||
|
@ -102,10 +102,15 @@ def test_link_headers(api):
|
||||||
|
|
||||||
_id='abc1234'
|
_id='abc1234'
|
||||||
|
|
||||||
rmock.register_uri('GET', requests_mock.ANY, json=[{"foo": "bar"}], headers={"link":"""
|
rmock.register_uri(
|
||||||
<{base}/api/v1/timelines/tag/{tag}?max_id={_id}>; rel="next", <{base}/api/v1/timelines/tag/{tag}?since_id={_id}>; rel="prev"
|
'GET',
|
||||||
""".format(base=api.api_base_url, tag=UNLIKELY_HASHTAG, _id=_id).strip()
|
requests_mock.ANY,
|
||||||
})
|
json=[{"foo": "bar"}],
|
||||||
|
headers={
|
||||||
|
"link": f"<{api.api_base_url}/api/v1/timelines/tag/{UNLIKELY_HASHTAG}?max_id={_id}>; rel=\"next\", "
|
||||||
|
f"<{api.api_base_url}/api/v1/timelines/tag/{UNLIKELY_HASHTAG}?since_id={_id}>; rel=\"prev\""
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
resp = api.timeline_hashtag(UNLIKELY_HASHTAG)
|
resp = api.timeline_hashtag(UNLIKELY_HASHTAG)
|
||||||
assert resp._pagination_next['max_id'] == _id
|
assert resp._pagination_next['max_id'] == _id
|
||||||
|
|
|
@ -203,7 +203,7 @@ def test_scheduled_status_long_part1(api):
|
||||||
else:
|
else:
|
||||||
the_medium_term_future = datetime.datetime.now() + datetime.timedelta(minutes=6)
|
the_medium_term_future = datetime.datetime.now() + datetime.timedelta(minutes=6)
|
||||||
pickle.dump(the_medium_term_future.timestamp(), open("tests/cassettes_special/test_scheduled_status_long_datetimeobjects.pkl", 'wb'))
|
pickle.dump(the_medium_term_future.timestamp(), open("tests/cassettes_special/test_scheduled_status_long_datetimeobjects.pkl", 'wb'))
|
||||||
scheduled_toot = api.status_post("please ensure maximum headroom at " + str(the_medium_term_future), scheduled_at=the_medium_term_future)
|
scheduled_toot = api.status_post(f"please ensure maximum headroom at {the_medium_term_future}", scheduled_at=the_medium_term_future)
|
||||||
scheduled_toot_list = api.scheduled_statuses()
|
scheduled_toot_list = api.scheduled_statuses()
|
||||||
assert scheduled_toot.id in map(lambda x: x.id, scheduled_toot_list)
|
assert scheduled_toot.id in map(lambda x: x.id, scheduled_toot_list)
|
||||||
pickle.dump(scheduled_toot.params.text, open("tests/cassettes_special/test_scheduled_status_long_text.pkl", 'wb'))
|
pickle.dump(scheduled_toot.params.text, open("tests/cassettes_special/test_scheduled_status_long_text.pkl", 'wb'))
|
||||||
|
|
Ładowanie…
Reference in New Issue