parent
3ac8e59dec
commit
4df0c7882d
3 changed files with 34 additions and 9 deletions
21
toot/api.py
21
toot/api.py
|
@ -173,17 +173,17 @@ def get_next_path(headers):
|
||||||
return "?".join([parsed.path, parsed.query])
|
return "?".join([parsed.path, parsed.query])
|
||||||
|
|
||||||
|
|
||||||
def _timeline_generator(app, user, path, limit=20):
|
def _timeline_generator(app, user, path, params=None):
|
||||||
while path:
|
while path:
|
||||||
response = http.get(app, user, path)
|
response = http.get(app, user, path, params)
|
||||||
yield response.json()
|
yield response.json()
|
||||||
path = get_next_path(response.headers)
|
path = get_next_path(response.headers)
|
||||||
|
|
||||||
|
|
||||||
def _anon_timeline_generator(instance, path, limit=20):
|
def _anon_timeline_generator(instance, path, params=None):
|
||||||
while path:
|
while path:
|
||||||
url = "https://{}{}".format(instance, path)
|
url = "https://{}{}".format(instance, path)
|
||||||
response = http.anon_get(url, path)
|
response = http.anon_get(url, params)
|
||||||
yield response.json()
|
yield response.json()
|
||||||
path = get_next_path(response.headers)
|
path = get_next_path(response.headers)
|
||||||
|
|
||||||
|
@ -193,9 +193,16 @@ def home_timeline_generator(app, user, limit=20):
|
||||||
return _timeline_generator(app, user, path)
|
return _timeline_generator(app, user, path)
|
||||||
|
|
||||||
|
|
||||||
def public_timeline_generator(instance, limit=20):
|
def public_timeline_generator(instance, local=False, limit=20):
|
||||||
path = '/api/v1/timelines/public?limit={}'.format(limit)
|
path = '/api/v1/timelines/public'
|
||||||
return _anon_timeline_generator(instance, path)
|
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):
|
def upload_media(app, user, file):
|
||||||
|
|
|
@ -33,12 +33,21 @@ def timeline(app, user, args):
|
||||||
def curses(app, user, args):
|
def curses(app, user, args):
|
||||||
from toot.ui.app import TimelineApp
|
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):
|
if not args.public and (not app or not user):
|
||||||
raise ConsoleError("You must be logged in to view the home timeline.")
|
raise ConsoleError("You must be logged in to view the home timeline.")
|
||||||
|
|
||||||
if args.public:
|
if args.public:
|
||||||
instance = args.instance or app.instance
|
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:
|
else:
|
||||||
generator = api.home_timeline_generator(app, user)
|
generator = api.home_timeline_generator(app, user)
|
||||||
|
|
||||||
|
|
|
@ -193,10 +193,19 @@ READ_COMMANDS = [
|
||||||
"default": False,
|
"default": False,
|
||||||
"help": "Resolve non-local accounts",
|
"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"], {
|
(["-i", "--instance"], {
|
||||||
"type": str,
|
"type": str,
|
||||||
"help": 'instance from which to read (for public timeline only)',
|
"help": 'instance from which to read (for public timeline only)',
|
||||||
})
|
}),
|
||||||
],
|
],
|
||||||
require_auth=False,
|
require_auth=False,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue