aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-05 21:43:36 -0700
committerFuwn <[email protected]>2025-07-05 21:43:36 -0700
commit5b92fe29641b78eecb3990f9ce8fcc0dde8bc580 (patch)
tree30728b2946a969c981b573bb43773e991e39ad4c /src
parentfix(schedule): Handle cross-day relative time differences (diff)
downloadoguri-5b92fe29641b78eecb3990f9ce8fcc0dde8bc580.tar.xz
oguri-5b92fe29641b78eecb3990f9ce8fcc0dde8bc580.zip
feat(schedule): Exact time flag
Diffstat (limited to 'src')
-rw-r--r--src/oguri/cli.py7
-rw-r--r--src/oguri/schedule.py29
2 files changed, 29 insertions, 7 deletions
diff --git a/src/oguri/cli.py b/src/oguri/cli.py
index 3410610..c2224b9 100644
--- a/src/oguri/cli.py
+++ b/src/oguri/cli.py
@@ -14,7 +14,10 @@ def cli():
@cli.command(aliases=["s"])
@click.argument("day", required=False, default="today")
@click.option("--reverse", is_flag=True, help="Reverse the order of the schedule.")
-def schedule(day, reverse):
+ "--exact", is_flag=True, help="Show exact airing times instead of relative times."
+)
+def schedule(day, reverse, exact):
"""
Shows the airing schedule for a given day.
@@ -35,7 +38,7 @@ def schedule(day, reverse):
'DAY must be "today", "tomorrow", "yesterday", or an integer.'
)
- asyncio.run(schedule_logic.show_schedule(days_offset, reverse))
+ asyncio.run(schedule_logic.show_schedule(days_offset, reverse, exact))
def main_script():
diff --git a/src/oguri/schedule.py b/src/oguri/schedule.py
index 07507a8..ad718da 100644
--- a/src/oguri/schedule.py
+++ b/src/oguri/schedule.py
@@ -11,7 +11,9 @@ from anilist_client.custom_fields import (
from anilist_client.custom_queries import Query
-async def show_schedule(days_offset: int, reverse_order: bool = False):
+async def show_schedule(
+ days_offset: int, reverse_order: bool = False, exact_time: bool = False
+):
client = Client(url="https://graphql.anilist.co")
start_of_day = datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
@@ -78,7 +80,9 @@ async def show_schedule(days_offset: int, reverse_order: bool = False):
airing_at_date = datetime.fromtimestamp(airing_at)
airing_time_string = ""
- if datetime.now() > airing_at_date:
+ if exact_time:
+ airing_time_string = format_exact_time(airing_at_date)
+ elif datetime.now() > airing_at_date:
airing_time_string = (
f"Aired {relative_time(airing_at_date)}"
)
@@ -98,12 +102,27 @@ async def show_schedule(days_offset: int, reverse_order: bool = False):
print(exception)
+def format_exact_time(date):
+ day = date.day
+ hour = date.strftime("%I").lstrip("0")
+ minute = date.strftime("%M")
+
+ if minute == "00":
+ minute_string = ""
+ else:
+ minute_string = f":{minute}"
+
+ am_pm = date.strftime("%p").replace("AM", "a.m.").replace("PM", "p.m.")
+
+ return date.strftime(f"%A, %B {day}, %Y, at {hour}{minute_string} {am_pm}")
+
+
def format_future_airing_time(date):
now = datetime.now()
delta = date - now
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes, _ = divmod(remainder, 60)
- time_str = date.strftime("%I:%M %p")
+ time_string = date.strftime("%I:%M %p").replace("AM", "a.m.").replace("PM", "p.m.")
parts = []
if hours > 0:
@@ -112,9 +131,9 @@ def format_future_airing_time(date):
parts.append(f"{minutes}m")
if not parts:
- return f"Airing soon at {time_str}"
+ return f"Airing soon at {time_string}"
- return f"In {' '.join(parts)} at {time_str}"
+ return f"In {' '.join(parts)} at {time_string}"
def relative_time(date):