kopia lustrzana https://github.com/ihabunek/toot
aiohttp
rodzic
1439e60c5f
commit
167c74df84
|
@ -1,5 +1,7 @@
|
||||||
coverage
|
coverage
|
||||||
|
ipython
|
||||||
keyring
|
keyring
|
||||||
|
pudb
|
||||||
pyxdg
|
pyxdg
|
||||||
pyyaml
|
pyyaml
|
||||||
sphinx
|
sphinx
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
flake8
|
flake8
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
pytest
|
pytest
|
||||||
|
pytest-cov
|
||||||
pytest-xdist[psutil]
|
pytest-xdist[psutil]
|
||||||
vermin
|
vermin
|
||||||
|
|
26
toot/aapi.py
26
toot/aapi.py
|
@ -1,4 +1,6 @@
|
||||||
|
import re
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from urllib.parse import urlparse
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from toot import Context
|
from toot import Context
|
||||||
|
@ -126,3 +128,27 @@ async def get_status(ctx: Context, status_id) -> Response:
|
||||||
async def get_status_context(ctx: Context, status_id) -> Response:
|
async def get_status_context(ctx: Context, status_id) -> Response:
|
||||||
url = f"/api/v1/statuses/{status_id}/context"
|
url = f"/api/v1/statuses/{status_id}/context"
|
||||||
return await request(ctx, "GET", url)
|
return await request(ctx, "GET", url)
|
||||||
|
|
||||||
|
|
||||||
|
# Timelines
|
||||||
|
|
||||||
|
async def home_timeline_generator(ctx: Context, limit=20):
|
||||||
|
path = "/api/v1/timelines/home"
|
||||||
|
params = {"limit": limit}
|
||||||
|
return _timeline_generator(ctx, path, params)
|
||||||
|
|
||||||
|
|
||||||
|
async def _timeline_generator(ctx: Context, path: str, params=None):
|
||||||
|
while path:
|
||||||
|
response = await request(ctx, "GET", path, params=params)
|
||||||
|
yield response.json
|
||||||
|
path = _get_next_path(response.headers)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_next_path(headers: dict):
|
||||||
|
"""Given timeline response headers, returns the path to the next batch"""
|
||||||
|
links = headers.get('Link', '')
|
||||||
|
matches = re.match('<([^>]+)>; rel="next"', links)
|
||||||
|
if matches:
|
||||||
|
parsed = urlparse(matches.group(1))
|
||||||
|
return "?".join([parsed.path, parsed.query])
|
||||||
|
|
|
@ -16,7 +16,7 @@ from toot.tui.utils import parse_datetime
|
||||||
from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY
|
from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY
|
||||||
|
|
||||||
|
|
||||||
def get_timeline_generator(app, user, args):
|
async def get_timeline_generator(ctx, args):
|
||||||
if len([arg for arg in [args.tag, args.list, args.public, args.account] if arg]) > 1:
|
if len([arg for arg in [args.tag, args.list, args.public, args.account] if arg]) > 1:
|
||||||
raise ConsoleError("Only one of --public, --tag, --account, or --list can be used at one time.")
|
raise ConsoleError("Only one of --public, --tag, --account, or --list can be used at one time.")
|
||||||
|
|
||||||
|
@ -26,35 +26,30 @@ def get_timeline_generator(app, user, args):
|
||||||
if args.instance and not (args.public or args.tag):
|
if args.instance and not (args.public or args.tag):
|
||||||
raise ConsoleError("The --instance option is only valid alongside --public or --tag.")
|
raise ConsoleError("The --instance option is only valid alongside --public or --tag.")
|
||||||
|
|
||||||
if args.public:
|
return await aapi.home_timeline_generator(ctx, limit=args.count)
|
||||||
if args.instance:
|
# if args.public:
|
||||||
return api.anon_public_timeline_generator(args.instance, local=args.local, limit=args.count)
|
# if args.instance:
|
||||||
else:
|
# return api.anon_public_timeline_generator(args.instance, local=args.local, limit=args.count)
|
||||||
return api.public_timeline_generator(app, user, local=args.local, limit=args.count)
|
# else:
|
||||||
elif args.tag:
|
# return api.public_timeline_generator(app, user, local=args.local, limit=args.count)
|
||||||
if args.instance:
|
# elif args.tag:
|
||||||
return api.anon_tag_timeline_generator(args.instance, args.tag, limit=args.count)
|
# if args.instance:
|
||||||
else:
|
# return api.anon_tag_timeline_generator(args.instance, args.tag, limit=args.count)
|
||||||
return api.tag_timeline_generator(app, user, args.tag, local=args.local, limit=args.count)
|
# else:
|
||||||
elif args.account:
|
# return api.tag_timeline_generator(app, user, args.tag, local=args.local, limit=args.count)
|
||||||
return api.account_timeline_generator(app, user, args.account, limit=args.count)
|
# elif args.account:
|
||||||
elif args.list:
|
# return api.account_timeline_generator(app, user, args.account, limit=args.count)
|
||||||
return api.timeline_list_generator(app, user, args.list, limit=args.count)
|
# elif args.list:
|
||||||
else:
|
# return api.timeline_list_generator(app, user, args.list, limit=args.count)
|
||||||
return api.home_timeline_generator(app, user, limit=args.count)
|
# else:
|
||||||
|
# return api.home_timeline_generator(app, user, limit=args.count)
|
||||||
|
|
||||||
|
|
||||||
def timeline(app, user, args, generator=None):
|
async def timeline(ctx: Context, args, generator=None):
|
||||||
if not generator:
|
if not generator:
|
||||||
generator = get_timeline_generator(app, user, args)
|
generator = await get_timeline_generator(ctx, args)
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
items = next(generator)
|
|
||||||
except StopIteration:
|
|
||||||
print_out("That's all folks.")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
async for items in generator:
|
||||||
if args.reverse:
|
if args.reverse:
|
||||||
items = reversed(items)
|
items = reversed(items)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue