Use Ruff and fix all its warnings and errors
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
"""
|
||||
calculate(job) - Calculates how many days, hours and minutes till trigger.
|
||||
"""
|
||||
import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytz
|
||||
from apscheduler.job import Job
|
||||
@ -11,8 +8,7 @@ from discord_reminder_bot.settings import config_timezone
|
||||
|
||||
|
||||
def calculate(job: Job) -> str:
|
||||
"""Get trigger time from a reminder and calculate how many days,
|
||||
hours and minutes till trigger.
|
||||
"""Get trigger time from a reminder and calculate how many days, hours and minutes till trigger.
|
||||
|
||||
Days/Minutes will not be included if 0.
|
||||
|
||||
@ -25,10 +21,7 @@ def calculate(job: Job) -> str:
|
||||
# TODO: This "breaks" when only seconds are left.
|
||||
# If we use (in {calc_countdown(job)}) it will show (in )
|
||||
|
||||
if type(job.trigger) is DateTrigger:
|
||||
trigger_time = job.trigger.run_date
|
||||
else:
|
||||
trigger_time = job.next_run_time
|
||||
trigger_time: datetime | None = job.trigger.run_date if type(job.trigger) is DateTrigger else job.next_run_time
|
||||
|
||||
# Get_job() returns None when it can't find a job with that ID.
|
||||
if trigger_time is None:
|
||||
@ -41,8 +34,7 @@ def calculate(job: Job) -> str:
|
||||
|
||||
|
||||
def countdown(trigger_time: datetime) -> str:
|
||||
"""
|
||||
Calculate days, hours and minutes to a date.
|
||||
"""Calculate days, hours and minutes to a date.
|
||||
|
||||
Args:
|
||||
trigger_time: The date.
|
||||
@ -50,7 +42,7 @@ def countdown(trigger_time: datetime) -> str:
|
||||
Returns:
|
||||
A string with the days, hours and minutes.
|
||||
"""
|
||||
countdown_time = trigger_time - datetime.datetime.now(tz=pytz.timezone(config_timezone))
|
||||
countdown_time: timedelta = trigger_time - datetime.now(tz=pytz.timezone(config_timezone))
|
||||
|
||||
days, hours, minutes = (
|
||||
countdown_time.days,
|
||||
@ -60,7 +52,7 @@ def countdown(trigger_time: datetime) -> str:
|
||||
|
||||
# Return seconds if only seconds are left.
|
||||
if days == 0 and hours == 0 and minutes == 0:
|
||||
seconds = countdown_time.seconds % 60
|
||||
seconds: int = countdown_time.seconds % 60
|
||||
return f"{seconds} second" + ("s" if seconds != 1 else "")
|
||||
|
||||
# TODO: Explain this.
|
||||
|
Reference in New Issue
Block a user