Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Nov 30, 2023
1 parent d8c7084 commit 28f3654
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
Empty file.
3 changes: 2 additions & 1 deletion toot/cli/__init__.py
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 *
87 changes: 87 additions & 0 deletions toot/cli/timelines.py
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)

0 comments on commit 28f3654

Please sign in to comment.