tz-aware
This commit is contained in:
parent
47e2fa5ccb
commit
437857c735
1 changed files with 10 additions and 4 deletions
14
ics-now.py
14
ics-now.py
|
@ -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
|
It depends on the nice ics-query https://github.com/niccokunzmann/ics-query
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
@ -13,11 +14,17 @@ from argparse import ArgumentParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
|
|
||||||
|
import pytz
|
||||||
from icalendar import Calendar, Event
|
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:
|
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:
|
def parse_minutes(s: str) -> datetime.timedelta:
|
||||||
|
@ -28,10 +35,9 @@ class IcsNow:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.parser = ArgumentParser()
|
self.parser = ArgumentParser()
|
||||||
self.parser.add_argument("ics", type=Path)
|
self.parser.add_argument("ics", type=Path)
|
||||||
self.parser.add_argument("--tz", default="Europe/Rome")
|
|
||||||
self.parser.add_argument(
|
self.parser.add_argument(
|
||||||
"--now",
|
"--now",
|
||||||
default=datetime.datetime.now(),
|
default=datetime.datetime.now(pytz.timezone(TZ)),
|
||||||
type=parse_dt,
|
type=parse_dt,
|
||||||
help="Simulate different time. Mostly for debug",
|
help="Simulate different time. Mostly for debug",
|
||||||
)
|
)
|
||||||
|
@ -55,7 +61,7 @@ class IcsNow:
|
||||||
self.args.ics_query,
|
self.args.ics_query,
|
||||||
cmd,
|
cmd,
|
||||||
"--tz",
|
"--tz",
|
||||||
self.args.tz,
|
TZ,
|
||||||
"--component",
|
"--component",
|
||||||
"VEVENT",
|
"VEVENT",
|
||||||
*args,
|
*args,
|
||||||
|
|
Loading…
Reference in a new issue