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

ENH: Add local and tag timeline support to curses

Closes #61
This commit is contained in:
ksunden 2019-01-02 22:36:40 -06:00
parent 3ac8e59dec
commit 4df0c7882d
3 changed files with 34 additions and 9 deletions

View File

@ -173,17 +173,17 @@ def get_next_path(headers):
return "?".join([parsed.path, parsed.query])
def _timeline_generator(app, user, path, limit=20):
def _timeline_generator(app, user, path, params=None):
while path:
response = http.get(app, user, path)
response = http.get(app, user, path, params)
yield response.json()
path = get_next_path(response.headers)
def _anon_timeline_generator(instance, path, limit=20):
def _anon_timeline_generator(instance, path, params=None):
while path:
url = "https://{}{}".format(instance, path)
response = http.anon_get(url, path)
response = http.anon_get(url, params)
yield response.json()
path = get_next_path(response.headers)
@ -193,9 +193,16 @@ def home_timeline_generator(app, user, limit=20):
return _timeline_generator(app, user, path)
def public_timeline_generator(instance, limit=20):
path = '/api/v1/timelines/public?limit={}'.format(limit)
return _anon_timeline_generator(instance, path)
def public_timeline_generator(instance, local=False, limit=20):
path = '/api/v1/timelines/public'
params = {'local': 'true' if local else 'false', '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}
return _timeline_generator(app, user, path, params)
def upload_media(app, user, file):

View File

@ -33,12 +33,21 @@ def timeline(app, user, args):
def curses(app, user, args):
from toot.ui.app import TimelineApp
# Make sure tag, list and public are not used simultaneously
if len([arg for arg in [args.tag, args.public] if arg]) > 1:
raise ConsoleError("Only one of --public or --tag 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 not args.public and (not app or not user):
raise ConsoleError("You must be logged in to view the home timeline.")
if args.public:
instance = args.instance or app.instance
generator = api.public_timeline_generator(instance)
generator = api.public_timeline_generator(instance, local=args.local)
elif args.tag:
generator = api.tag_timeline_generator(app, user, args.tag, local=args.local)
else:
generator = api.home_timeline_generator(app, user)

View File

@ -193,10 +193,19 @@ READ_COMMANDS = [
"default": False,
"help": "Resolve non-local accounts",
}),
(["-t", "--tag"], {
"type": str,
"help": "Show timeline for given hashtag.",
}),
(["-l", "--local"], {
"action": "store_true",
"default": False,
"help": "Show only statuses from local instance (public and tag timelines only).",
}),
(["-i", "--instance"], {
"type": str,
"help": 'instance from which to read (for public timeline only)',
})
}),
],
require_auth=False,
),