-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from toot.cli.base import cli, Context # noqa | ||
|
||
from toot.cli.auth import * | ||
from toot.cli.accounts import * | ||
from toot.cli.auth import * | ||
from toot.cli.lists import * | ||
from toot.cli.post import * | ||
from toot.cli.read import * | ||
from toot.cli.statuses import * | ||
from toot.cli.tags import * | ||
from toot.cli.timelines import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import click | ||
|
||
from toot import api, App, User | ||
from toot.cli.base import cli, pass_context, Context | ||
from typing import Optional | ||
|
||
from toot.entities import Status, from_dict | ||
from toot.output import print_timeline | ||
|
||
|
||
@cli.command() | ||
@click.option("--account", "-a", help="Show account timeline") | ||
@click.option("--instance", "-i", help="Instance from which to read (public and tag timelines only)") | ||
@click.option("--list", help="Show list timeline") | ||
@click.option("--local", "-l", is_flag=True, help="Show only statuses from the local instance (public and tag timelines only)") | ||
@click.option("--public", "-p", is_flag=True, help="Show public timeline") | ||
@click.option("--tag", "-t", help="Show hashtag timeline") | ||
@pass_context | ||
def timeline( | ||
ctx: Context, | ||
account: Optional[str], | ||
instance: Optional[str], | ||
list: Optional[str], | ||
local: bool, | ||
public: bool, | ||
tag: Optional[str], | ||
): | ||
"""Show recent statuses in a timeline""" | ||
generator = get_timeline_generator(ctx.app, ctx.user, account, instance, list, local, public, tag) | ||
|
||
while True: | ||
try: | ||
items = next(generator) | ||
except StopIteration: | ||
click.echo("That's all folks.") | ||
return | ||
|
||
# if args.reverse: | ||
# items = reversed(items) | ||
|
||
statuses = [from_dict(Status, item) for item in items] | ||
print_timeline(statuses) | ||
|
||
# if args.once or not sys.stdout.isatty(): | ||
# break | ||
|
||
char = input("\nContinue? [Y/n] ") | ||
if char.lower() == "n": | ||
break | ||
|
||
|
||
def get_timeline_generator( | ||
app: App, | ||
user: User, | ||
account: Optional[str], | ||
instance: Optional[str], | ||
list: Optional[str], | ||
local: bool, | ||
public: bool, | ||
tag: Optional[str], | ||
limit=20, # TODO | ||
): | ||
if len([arg for arg in [tag, list, public, account] if arg]) > 1: | ||
raise click.ClickException("Only one of --public, --tag, --account, or --list can be used at one time.") | ||
|
||
if local and not (public or tag): | ||
raise click.ClickException("The --local option is only valid alongside --public or --tag.") | ||
|
||
if instance and not (public or tag): | ||
raise click.ClickException("The --instance option is only valid alongside --public or --tag.") | ||
|
||
if public: | ||
if instance: | ||
return api.anon_public_timeline_generator(instance, local=local, limit=limit) | ||
else: | ||
return api.public_timeline_generator(app, user, local=local, limit=limit) | ||
elif tag: | ||
if instance: | ||
return api.anon_tag_timeline_generator(instance, tag, limit=limit) | ||
else: | ||
return api.tag_timeline_generator(app, user, tag, local=local, limit=limit) | ||
elif account: | ||
return api.account_timeline_generator(app, user, account, limit=limit) | ||
elif list: | ||
return api.timeline_list_generator(app, user, list, limit=limit) | ||
else: | ||
return api.home_timeline_generator(app, user, limit=limit) |