1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-06-23 06:25:26 +00:00

Merge pull request #85 from ksunden/localtag

Add local and tag timelines to curses
This commit is contained in:
Ivan Habunek 2019-01-24 11:20:58 +01:00 committed by GitHub
commit c7c42b8337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 9 deletions

View File

@ -179,17 +179,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)
@ -199,9 +199,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

@ -46,12 +46,21 @@ def thread(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

@ -203,10 +203,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,
),