diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/oguri/cli.py | 13 | ||||
| -rw-r--r-- | src/oguri/schedule.py | 11 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/oguri/cli.py b/src/oguri/cli.py index 39ed026..c3327f6 100644 --- a/src/oguri/cli.py +++ b/src/oguri/cli.py @@ -18,7 +18,14 @@ def cli(): "--exact", is_flag=True, help="Show exact airing times instead of relative times." ) @click.option("--first", is_flag=True, help="Show only first airing episodes.") -def schedule(day, reverse, exact, first): + "--sort", + "sort_by", + type=click.Choice(["time", "episode"], case_sensitive=False), + default="time", + help="Sort the schedule by time or episode.", +) +def schedule(day, reverse, exact, first, sort_by): """ Shows the airing schedule for a given day. @@ -39,7 +46,9 @@ def schedule(day, reverse, exact, first): 'DAY must be "today", "tomorrow", "yesterday", or an integer.' ) - asyncio.run(schedule_logic.show_schedule(days_offset, reverse, exact, first)) + asyncio.run( + schedule_logic.show_schedule(days_offset, reverse, exact, first, sort_by) + ) def main_script(): diff --git a/src/oguri/schedule.py b/src/oguri/schedule.py index bfc12b9..c6f837a 100644 --- a/src/oguri/schedule.py +++ b/src/oguri/schedule.py @@ -16,6 +16,7 @@ async def show_schedule( reverse_order: bool = False, exact_time: bool = False, first_episode_only: bool = False, + sort_by: str = "time", ): client = Client(url="https://graphql.anilist.co") start_of_day = datetime.now().replace( @@ -53,11 +54,13 @@ async def show_schedule( airing_schedules = page.get("airingSchedules") if airing_schedules: - if reverse_order: - airing_schedules.sort(key=lambda x: x.get("airingAt")) - else: + if sort_by == "time": airing_schedules.sort( - key=lambda x: x.get("airingAt"), reverse=True + key=lambda x: x.get("airingAt"), reverse=not reverse_order + ) + elif sort_by == "episode": + airing_schedules.sort( + key=lambda x: x.get("episode"), reverse=not reverse_order ) console = Console() |