aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šedivý <[email protected]>2022-12-02 22:04:23 +0100
committerMiroslav Šedivý <[email protected]>2022-12-02 22:04:23 +0100
commit325cc917d5ad14b130b156d23b7adca46499dc24 (patch)
tree247b41199512db9693d00baf7522602805e31c3f /mastodon/accounts.py
parentc796cf39b01e38fe381fb4743988da991b072183 (diff)
downloadmastodon.py-325cc917d5ad14b130b156d23b7adca46499dc24.tar.gz
refactor: use f-strings
Diffstat (limited to 'mastodon/accounts.py')
-rw-r--r--mastodon/accounts.py59
1 files changed, 24 insertions, 35 deletions
diff --git a/mastodon/accounts.py b/mastodon/accounts.py
index 219edac..3d10088 100644
--- a/mastodon/accounts.py
+++ b/mastodon/accounts.py
@@ -66,7 +66,7 @@ class Mastodon(Internals):
66 response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False) 66 response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False)
67 temp_access_token = response['access_token'] 67 temp_access_token = response['access_token']
68 except Exception as e: 68 except Exception as e:
69 raise MastodonIllegalArgumentError('Invalid request during oauth phase: %s' % e) 69 raise MastodonIllegalArgumentError(f'Invalid request during oauth phase: {e}')
70 70
71 # Step 2: Use that to create a user 71 # Step 2: Use that to create a user
72 try: 72 try:
@@ -74,7 +74,7 @@ class Mastodon(Internals):
74 if "error" in response: 74 if "error" in response:
75 if return_detailed_error: 75 if return_detailed_error:
76 return None, response 76 return None, response
77 raise MastodonIllegalArgumentError('Invalid request: %s' % e) 77 raise MastodonIllegalArgumentError(f'Invalid request: {e}')
78 self.access_token = response['access_token'] 78 self.access_token = response['access_token']
79 self.__set_refresh_token(response.get('refresh_token')) 79 self.__set_refresh_token(response.get('refresh_token'))
80 self.__set_token_expired(int(response.get('expires_in', 0))) 80 self.__set_token_expired(int(response.get('expires_in', 0)))
@@ -88,7 +88,10 @@ class Mastodon(Internals):
88 received_scopes += _SCOPE_SETS[scope_set] 88 received_scopes += _SCOPE_SETS[scope_set]
89 89
90 if not set(scopes) <= set(received_scopes): 90 if not set(scopes) <= set(received_scopes):
91 raise MastodonAPIError('Granted scopes "' + " ".join(received_scopes) + '" do not contain all of the requested scopes "' + " ".join(scopes) + '".') 91 raise MastodonAPIError(
92 f'Granted scopes "{" ".join(received_scopes)}" '
93 f'do not contain all of the requested scopes "{" ".join(scopes)}".'
94 )
92 95
93 if to_file is not None: 96 if to_file is not None:
94 with open(to_file, 'w') as token_file: 97 with open(to_file, 'w') as token_file:
@@ -124,8 +127,7 @@ class Mastodon(Internals):
124 Returns a :ref:`account dict <account dict>`. 127 Returns a :ref:`account dict <account dict>`.
125 """ 128 """
126 id = self.__unpack_id(id) 129 id = self.__unpack_id(id)
127 url = '/api/v1/accounts/{0}'.format(str(id)) 130 return self.__api_request('GET', f'/api/v1/accounts/{id}')
128 return self.__api_request('GET', url)
129 131
130 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 132 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
131 def account_verify_credentials(self): 133 def account_verify_credentials(self):
@@ -185,8 +187,7 @@ class Mastodon(Internals):
185 if not exclude_reblogs: 187 if not exclude_reblogs:
186 del params["exclude_reblogs"] 188 del params["exclude_reblogs"]
187 189
188 url = '/api/v1/accounts/{0}/statuses'.format(str(id)) 190 return self.__api_request('GET', f'/api/v1/accounts/{id}/statuses', params)
189 return self.__api_request('GET', url, params)
190 191
191 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) 192 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
192 def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None): 193 def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None):
@@ -206,8 +207,7 @@ class Mastodon(Internals):
206 since_id = self.__unpack_id(since_id, dateconv=True) 207 since_id = self.__unpack_id(since_id, dateconv=True)
207 208
208 params = self.__generate_params(locals(), ['id']) 209 params = self.__generate_params(locals(), ['id'])
209 url = '/api/v1/accounts/{0}/following'.format(str(id)) 210 return self.__api_request('GET', f'/api/v1/accounts/{id}/following', params)
210 return self.__api_request('GET', url, params)
211 211
212 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) 212 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
213 def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None): 213 def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None):
@@ -227,8 +227,7 @@ class Mastodon(Internals):
227 since_id = self.__unpack_id(since_id, dateconv=True) 227 since_id = self.__unpack_id(since_id, dateconv=True)
228 228
229 params = self.__generate_params(locals(), ['id']) 229 params = self.__generate_params(locals(), ['id'])
230 url = '/api/v1/accounts/{0}/followers'.format(str(id)) 230 return self.__api_request('GET', f'/api/v1/accounts/{id}/followers', params)
231 return self.__api_request('GET', url, params)
232 231
233 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 232 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
234 def account_relationships(self, id): 233 def account_relationships(self, id):
@@ -269,8 +268,7 @@ class Mastodon(Internals):
269 """ 268 """
270 id = self.__unpack_id(id) 269 id = self.__unpack_id(id)
271 params = self.__generate_params(locals(), ['id']) 270 params = self.__generate_params(locals(), ['id'])
272 url = '/api/v1/accounts/{0}/lists'.format(str(id)) 271 return self.__api_request('GET', f'/api/v1/accounts/{id}/lists', params)
273 return self.__api_request('GET', url, params)
274 272
275 @api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT) 273 @api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT)
276 def account_lookup(self, acct): 274 def account_lookup(self, acct):
@@ -317,8 +315,7 @@ class Mastodon(Internals):
317 if params["reblogs"] is None: 315 if params["reblogs"] is None:
318 del params["reblogs"] 316 del params["reblogs"]
319 317
320 url = '/api/v1/accounts/{0}/follow'.format(str(id)) 318 return self.__api_request('POST', f'/api/v1/accounts/{id}/follow', params)
321 return self.__api_request('POST', url, params)
322 319
323 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 320 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
324 def follows(self, uri): 321 def follows(self, uri):
@@ -338,7 +335,7 @@ class Mastodon(Internals):
338 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 335 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
339 """ 336 """
340 id = self.__unpack_id(id) 337 id = self.__unpack_id(id)
341 return self.__api_request('POST', '/api/v1/accounts/{0}/unfollow'.format(str(id))) 338 return self.__api_request('POST', f'/api/v1/accounts/{id}/unfollow')
342 339
343 @api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP) 340 @api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP)
344 def account_remove_from_followers(self, id): 341 def account_remove_from_followers(self, id):
@@ -349,7 +346,7 @@ class Mastodon(Internals):
349 Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status. 346 Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status.
350 """ 347 """
351 id = self.__unpack_id(id) 348 id = self.__unpack_id(id)
352 return self.__api_request('POST', '/api/v1/accounts/{0}/remove_from_followers'.format(str(id))) 349 return self.__api_request('POST', f'/api/v1/accounts/{id}/remove_from_followers')
353 350
354 351
355 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 352 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
@@ -360,8 +357,7 @@ class Mastodon(Internals):
360 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 357 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
361 """ 358 """
362 id = self.__unpack_id(id) 359 id = self.__unpack_id(id)
363 url = '/api/v1/accounts/{0}/block'.format(str(id)) 360 return self.__api_request('POST', f'/api/v1/accounts/{id}/block')
364 return self.__api_request('POST', url)
365 361
366 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 362 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
367 def account_unblock(self, id): 363 def account_unblock(self, id):
@@ -371,8 +367,7 @@ class Mastodon(Internals):
371 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 367 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
372 """ 368 """
373 id = self.__unpack_id(id) 369 id = self.__unpack_id(id)
374 url = '/api/v1/accounts/{0}/unblock'.format(str(id)) 370 return self.__api_request('POST', f'/api/v1/accounts/{id}/unblock')
375 return self.__api_request('POST', url)
376 371
377 @api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP) 372 @api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP)
378 def account_mute(self, id, notifications=True, duration=None): 373 def account_mute(self, id, notifications=True, duration=None):
@@ -387,8 +382,7 @@ class Mastodon(Internals):
387 """ 382 """
388 id = self.__unpack_id(id) 383 id = self.__unpack_id(id)
389 params = self.__generate_params(locals(), ['id']) 384 params = self.__generate_params(locals(), ['id'])
390 url = '/api/v1/accounts/{0}/mute'.format(str(id)) 385 return self.__api_request('POST', f'/api/v1/accounts/{id}/mute', params)
391 return self.__api_request('POST', url, params)
392 386
393 @api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 387 @api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
394 def account_unmute(self, id): 388 def account_unmute(self, id):
@@ -398,8 +392,7 @@ class Mastodon(Internals):
398 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 392 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
399 """ 393 """
400 id = self.__unpack_id(id) 394 id = self.__unpack_id(id)
401 url = '/api/v1/accounts/{0}/unmute'.format(str(id)) 395 return self.__api_request('POST', f'/api/v1/accounts/{id}/unmute', params)
402 return self.__api_request('POST', url)
403 396
404 @api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT) 397 @api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT)
405 def account_update_credentials(self, display_name=None, note=None, 398 def account_update_credentials(self, display_name=None, note=None,
@@ -436,10 +429,8 @@ class Mastodon(Internals):
436 429
437 fields_attributes = [] 430 fields_attributes = []
438 for idx, (field_name, field_value) in enumerate(fields): 431 for idx, (field_name, field_value) in enumerate(fields):
439 params_initial['fields_attributes[' + 432 params_initial[f'fields_attributes[{idx}][name]'] = field_name
440 str(idx) + '][name]'] = field_name 433 params_initial[f'fields_attributes[{idx}][value]'] = field_value
441 params_initial['fields_attributes[' +
442 str(idx) + '][value]'] = field_value
443 434
444 # Clean up params 435 # Clean up params
445 for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]: 436 for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]:
@@ -464,8 +455,7 @@ class Mastodon(Internals):
464 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 455 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
465 """ 456 """
466 id = self.__unpack_id(id) 457 id = self.__unpack_id(id)
467 url = '/api/v1/accounts/{0}/pin'.format(str(id)) 458 return self.__api_request('POST', f'/api/v1/accounts/{id}/pin')
468 return self.__api_request('POST', url)
469 459
470 @api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP) 460 @api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP)
471 def account_unpin(self, id): 461 def account_unpin(self, id):
@@ -475,8 +465,7 @@ class Mastodon(Internals):
475 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 465 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
476 """ 466 """
477 id = self.__unpack_id(id) 467 id = self.__unpack_id(id)
478 url = '/api/v1/accounts/{0}/unpin'.format(str(id)) 468 return self.__api_request('POST', f'/api/v1/accounts/{id}/unpin')
479 return self.__api_request('POST', url)
480 469
481 @api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP) 470 @api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP)
482 def account_note_set(self, id, comment): 471 def account_note_set(self, id, comment):
@@ -487,7 +476,7 @@ class Mastodon(Internals):
487 """ 476 """
488 id = self.__unpack_id(id) 477 id = self.__unpack_id(id)
489 params = self.__generate_params(locals(), ["id"]) 478 params = self.__generate_params(locals(), ["id"])
490 return self.__api_request('POST', '/api/v1/accounts/{0}/note'.format(str(id)), params) 479 return self.__api_request('POST', f'/api/v1/accounts/{id}/note', params)
491 480
492 @api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG) 481 @api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG)
493 def account_featured_tags(self, id): 482 def account_featured_tags(self, id):
@@ -497,4 +486,4 @@ class Mastodon(Internals):
497 Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_). 486 Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_).
498 """ 487 """
499 id = self.__unpack_id(id) 488 id = self.__unpack_id(id)
500 return self.__api_request('GET', '/api/v1/accounts/{0}/featured_tags'.format(str(id))) 489 return self.__api_request('GET', f'/api/v1/accounts/{id}/featured_tags')
Powered by cgit v1.2.3 (git 2.41.0)