1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Add support for tag and list timelines

This commit is contained in:
Ivan Habunek 2018-06-12 10:40:36 +02:00
parent 406943237a
commit e1cfda1acb
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
3 changed files with 45 additions and 8 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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,