next: allow shows to be late

This commit is contained in:
root 2024-12-28 15:58:44 +01:00
parent 437857c735
commit d4d266e7c5

View file

@ -48,6 +48,13 @@ class IcsNow:
default=parse_minutes(60),
help='How many minute should "next" include?',
)
self.parser.add_argument(
"--next-late",
metavar="DURATION",
type=parse_minutes,
default=parse_minutes(10),
help='How many minutes can the "next" show be late?',
)
self.parser.add_argument(
"--ics-query",
type=Path,
@ -78,8 +85,11 @@ class IcsNow:
# FIXME: sort by priority
return events[0]
def pick_next(self, events: list[Event], current) -> Event | None:
events.remove(current)
def pick_next(self, events: list[Event], current) -> Optional[Event]:
events = [
e for e in events
if e['DTSTART'].dt > (self.args.now - self.args.next_late)
]
if not events:
return None
events.sort(key=lambda e: e['DTSTART'].dt)