diff --git a/toot/api.py b/toot/api.py index 59622c2..a5bde26 100644 --- a/toot/api.py +++ b/toot/api.py @@ -2,7 +2,7 @@ import re -from urllib.parse import urlparse, urlencode +from urllib.parse import urlparse, urlencode, quote from toot import http, CLIENT_NAME, CLIENT_WEBSITE from toot.exceptions import AuthenticationError @@ -92,7 +92,19 @@ def timeline_home(app, user): def timeline_public(app, user, local=False): - return http.get(app, user, '/api/v1/timelines/public', {'local': 'true' if local else 'false'}).json() + params = {'local': 'true' if local else 'false'} + 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'} + return http.get(app, user, url, params).json() + + +def timeline_list(app, user, list_id): + url = '/api/v1/timelines/list/{}'.format(list_id) + return http.get(app, user, url).json() def get_next_path(headers): diff --git a/toot/commands.py b/toot/commands.py index 16b44a3..6fcad6f 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -8,10 +8,22 @@ from toot.utils import assert_domain_exists def timeline(app, user, args): - if args.local: - items = api.timeline_public(app, user, local=True) + # Make sure tag, list and public are not used simultaneously + if len([arg for arg in [args.tag, args.list_id, args.public] if arg]) > 1: + raise ConsoleError("Only one of --public --tag --list-id can be used at one time.") + + if args.local and not (args.public or args.tag): + raise ConsoleError("The --local option is only valid alongside --public or --tag.") + + if args.public: + items = api.timeline_public(app, user, local=args.local) + elif args.tag: + items = api.timeline_tag(app, user, args.tag, local=args.local) + elif args.list_id: + items = api.timeline_list(app, user, args.list_id) else: items = api.timeline_home(app, user) + print_timeline(items) diff --git a/toot/console.py b/toot/console.py index 80d3a45..fa47bd6 100644 --- a/toot/console.py +++ b/toot/console.py @@ -131,12 +131,25 @@ READ_COMMANDS = [ ), Command( name="timeline", - description="Show recent items in your public timeline", + description="Show recent items in a timeline (home by default)", arguments=[ - (["-l", "--local"], { - "action": 'store_true', + (["-p", "--public"], { + "action": "store_true", "default": False, - "help": "Show local timeline instead of public timeline.", + "help": "Show public timeline.", + }), + (["-t", "--tag"], { + "type": str, + "help": "Show timeline for given hashtag.", + }), + (["-i", "--list-id"], { + "type": int, + "help": "Show timeline for given list ID.", + }), + (["-l", "--local"], { + "action": "store_true", + "default": False, + "help": "Show only statuses from local instance (public and tag timelines only).", }), ], require_auth=True,