1
0
mirror of https://github.com/ihabunek/toot synced 2024-12-23 15:37:47 +01:00

Use fstrings instead of format

This commit is contained in:
Ivan Habunek 2023-01-02 10:12:42 +01:00
parent 02b6023a61
commit a83c3520ae
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D

View File

@ -11,25 +11,22 @@ SCOPES = 'read write follow'
def _account_action(app, user, account, action):
url = '/api/v1/accounts/{}/{}'.format(account, action)
url = f"/api/v1/accounts/{account}/{action}"
return http.post(app, user, url).json()
def _status_action(app, user, status_id, action, data=None):
url = '/api/v1/statuses/{}/{}'.format(status_id, action)
url = f"/api/v1/statuses/{status_id}/{action}"
return http.post(app, user, url, data=data).json()
def _tag_action(app, user, tag_name, action):
url = '/api/v1/tags/{}/{}'.format(tag_name, action)
url = f"/api/v1/tags/{tag_name}/{action}"
return http.post(app, user, url).json()
def create_app(domain, scheme='https'):
url = '{}://{}/api/v1/apps'.format(scheme, domain)
url = f"{scheme}://{domain}/api/v1/apps"
json = {
'client_name': CLIENT_NAME,
@ -180,7 +177,7 @@ def delete_status(app, user, status_id):
Deletes a status with given ID.
https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#deleting-a-status
"""
return http.delete(app, user, '/api/v1/statuses/{}'.format(status_id))
return http.delete(app, user, f"/api/v1/statuses/{status_id}")
def favourite(app, user, status_id):
@ -220,14 +217,12 @@ def translate(app, user, status_id):
def context(app, user, status_id):
url = '/api/v1/statuses/{}/context'.format(status_id)
url = f"/api/v1/statuses/{status_id}/context"
return http.get(app, user, url).json()
def reblogged_by(app, user, status_id):
url = '/api/v1/statuses/{}/reblogged_by'.format(status_id)
url = f"/api/v1/statuses/{status_id}/reblogged_by"
return http.get(app, user, url).json()
@ -248,7 +243,7 @@ def _timeline_generator(app, user, path, params=None):
def home_timeline_generator(app, user, limit=20):
path = '/api/v1/timelines/home?limit={}'.format(limit)
path = f"/api/v1/timelines/home?limit={limit}"
return _timeline_generator(app, user, path)
@ -259,7 +254,7 @@ def public_timeline_generator(app, user, local=False, limit=20):
def tag_timeline_generator(app, user, hashtag, local=False, limit=20):
path = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
path = f"/api/v1/timelines/tag/{quote(hashtag)}"
params = {'local': str_bool(local), 'limit': limit}
return _timeline_generator(app, user, path, params)
@ -271,13 +266,13 @@ def bookmark_timeline_generator(app, user, limit=20):
def timeline_list_generator(app, user, list_id, limit=20):
path = '/api/v1/timelines/list/{}'.format(list_id)
path = f"/api/v1/timelines/list/{list_id}"
return _timeline_generator(app, user, path, {'limit': limit})
def _anon_timeline_generator(instance, path, params=None):
while path:
url = "https://{}{}".format(instance, path)
url = f"https://{instance}{path}"
response = http.anon_get(url, params)
yield response.json()
path = _get_next_path(response.headers)
@ -290,7 +285,7 @@ def anon_public_timeline_generator(instance, local=False, limit=20):
def anon_tag_timeline_generator(instance, hashtag, local=False, limit=20):
path = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
path = f"/api/v1/timelines/tag/{quote(hashtag)}"
params = {'local': str_bool(local), 'limit': limit}
return _anon_timeline_generator(instance, path, params)
@ -340,12 +335,12 @@ def _get_response_list(app, user, path):
def following(app, user, account):
path = '/api/v1/accounts/{}/{}'.format(account, 'following')
path = f"/api/v1/accounts/{account}/following"
return _get_response_list(app, user, path)
def followers(app, user, account):
path = '/api/v1/accounts/{}/{}'.format(account, 'followers')
path = f"/api/v1/accounts/{account}/followers"
return _get_response_list(app, user, path)
@ -375,8 +370,7 @@ def verify_credentials(app, user):
def single_status(app, user, status_id):
url = '/api/v1/statuses/{}'.format(status_id)
url = f"/api/v1/statuses/{status_id}"
return http.get(app, user, url).json()
@ -390,5 +384,5 @@ def clear_notifications(app, user):
def get_instance(domain, scheme="https"):
url = "{}://{}/api/v1/instance".format(scheme, domain)
url = f"{scheme}://{domain}/api/v1/instance"
return http.anon_get(url).json()