Skip to content

Commit

Permalink
Make boolen params a bit less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Jan 24, 2019
1 parent c7c42b8 commit 32b1c67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions toot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from toot import http, CLIENT_NAME, CLIENT_WEBSITE
from toot.exceptions import AuthenticationError
from toot.utils import str_bool

SCOPES = 'read write follow'

Expand Down Expand Up @@ -106,7 +107,7 @@ def post_status(
'status': status,
'media_ids[]': media_ids,
'visibility': visibility,
'sensitive': "true" if sensitive else "false",
'sensitive': str_bool(sensitive),
'spoiler_text': spoiler_text,
'in_reply_to_id': in_reply_to_id,
}, headers=headers).json()
Expand Down Expand Up @@ -155,13 +156,13 @@ def timeline_home(app, user):


def timeline_public(app, user, local=False):
params = {'local': 'true' if local else 'false'}
params = {'local': str_bool(local)}
return http.get(app, user, '/api/v1/timelines/public', params).json()


def timeline_tag(app, user, hashtag, local=False):
url = '/api/v1/timelines/tag/{}'.format(quote(hashtag))
params = {'local': 'true' if local else 'false'}
params = {'local': str_bool(local)}
return http.get(app, user, url, params).json()


Expand Down Expand Up @@ -201,13 +202,13 @@ def home_timeline_generator(app, user, limit=20):

def public_timeline_generator(instance, local=False, limit=20):
path = '/api/v1/timelines/public'
params = {'local': 'true' if local else 'false', 'limit': limit}
params = {'local': str_bool(local), 'limit': limit}
return _anon_timeline_generator(instance, path, params)


def tag_timeline_generator(app, user, hashtag, local=False, limit=20):
path = '/api/v1/timelines/tag/{}'.format(hashtag)
params = {'local': 'true' if local else 'false', 'limit': limit}
params = {'local': str_bool(local), 'limit': limit}
return _timeline_generator(app, user, path, params)


Expand Down
5 changes: 5 additions & 0 deletions toot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from toot.exceptions import ConsoleError


def str_bool(b):
"""Convert boolean to string, in the way expected by the API."""
return "true" if b else "false"


def get_text(html):
"""Converts html to text, strips all tags."""
text = BeautifulSoup(html.replace(''', "'"), "html.parser").get_text()
Expand Down

0 comments on commit 32b1c67

Please sign in to comment.