This commit is contained in:
root 2024-12-28 15:57:56 +01:00
parent 47e2fa5ccb
commit 437857c735

View file

@ -6,6 +6,7 @@ This script yields JSON info about the current event + the next one.
It depends on the nice ics-query https://github.com/niccokunzmann/ics-query
"""
import os
import datetime
import json
import sys
@ -13,11 +14,17 @@ from argparse import ArgumentParser
from pathlib import Path
from subprocess import check_output
import pytz
from icalendar import Calendar, Event
TZ = os.getenv('TZ')
if TZ is None:
TZ = check_output('timedatectl show -p Timezone --value'.split()).strip()
def parse_dt(s: str) -> datetime.datetime:
return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S")
dt = datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S")
dt = pytz.timezone(TZ).localize(dt)
return dt
def parse_minutes(s: str) -> datetime.timedelta:
@ -28,10 +35,9 @@ class IcsNow:
def __init__(self):
self.parser = ArgumentParser()
self.parser.add_argument("ics", type=Path)
self.parser.add_argument("--tz", default="Europe/Rome")
self.parser.add_argument(
"--now",
default=datetime.datetime.now(),
default=datetime.datetime.now(pytz.timezone(TZ)),
type=parse_dt,
help="Simulate different time. Mostly for debug",
)
@ -55,7 +61,7 @@ class IcsNow:
self.args.ics_query,
cmd,
"--tz",
self.args.tz,
TZ,
"--component",
"VEVENT",
*args,