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:
parent
406943237a
commit
e1cfda1acb
16
toot/api.py
16
toot/api.py
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import re
|
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 import http, CLIENT_NAME, CLIENT_WEBSITE
|
||||||
from toot.exceptions import AuthenticationError
|
from toot.exceptions import AuthenticationError
|
||||||
@ -92,7 +92,19 @@ def timeline_home(app, user):
|
|||||||
|
|
||||||
|
|
||||||
def timeline_public(app, user, local=False):
|
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):
|
def get_next_path(headers):
|
||||||
|
@ -8,10 +8,22 @@ from toot.utils import assert_domain_exists
|
|||||||
|
|
||||||
|
|
||||||
def timeline(app, user, args):
|
def timeline(app, user, args):
|
||||||
if args.local:
|
# Make sure tag, list and public are not used simultaneously
|
||||||
items = api.timeline_public(app, user, local=True)
|
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:
|
else:
|
||||||
items = api.timeline_home(app, user)
|
items = api.timeline_home(app, user)
|
||||||
|
|
||||||
print_timeline(items)
|
print_timeline(items)
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,12 +131,25 @@ READ_COMMANDS = [
|
|||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
name="timeline",
|
name="timeline",
|
||||||
description="Show recent items in your public timeline",
|
description="Show recent items in a timeline (home by default)",
|
||||||
arguments=[
|
arguments=[
|
||||||
(["-l", "--local"], {
|
(["-p", "--public"], {
|
||||||
"action": 'store_true',
|
"action": "store_true",
|
||||||
"default": False,
|
"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,
|
require_auth=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user