diff options
author | Christian Franke <nobody@nowhere.ws> | 2016-05-02 14:36:12 +0200 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2016-05-02 14:36:12 +0200 |
commit | 04f537fd010b95c2cd543bee9de64bba8271c01b (patch) | |
tree | 69f83e4fefcf7f7cf74d748e67b81a5fc0d6098d | |
parent | 16c06102404d7c0ca35167f47312343e513582fe (diff) |
Use timezone in calendar script
-rw-r--r-- | scripts/get_calendar.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py index 89daf07..20a8b6f 100644 --- a/scripts/get_calendar.py +++ b/scripts/get_calendar.py @@ -11,6 +11,9 @@ import os from dateutil.rrule import rrulestr import icalendar import subprocess +import pytz + +berlin = pytz.timezone('Europe/Berlin') def fetch_calendar(logger): """Fetches the calendar events and returns a icalendar.Calendar instance. @@ -81,6 +84,10 @@ def get_events(calendar, after, before): if end.hour == 0 and end.minute == 0 and end.second == 0: end -= timedelta(seconds=1) + if start.tzinfo is None: + start = berlin.localize(start) + if end.tzinfo is None: + end = berlin.localize(end) if 'rrule' in event: rrule = rrulestr(event['rrule'].to_ical(), dtstart=start) duration = end - start @@ -131,15 +138,15 @@ if __name__ == '__main__': logging.basicConfig(stream=sys.stderr, level=logging.ERROR) logger = logging.getLogger('calendar_feed') regen, calendar = fetch_calendar(logger) - now = datetime.now() + now = berlin.localize(datetime.now()) after = now - relativedelta(days=1) before = now + relativedelta(months=+1) - after_tab = datetime(now.year,now.month,1); + after_tab = berlin.localize(datetime(now.year,now.month,1)) if now.month + 2 > 12: - before_tab = datetime(now.year+1,now.month + 10,1) + before_tab = berlin.localize(datetime(now.year+1,now.month + 10,1)) else: - before_tab = datetime(now.year,now.month+2,1) + before_tab = berlin.localize(datetime(now.year,now.month+2,1)) changed = put_events(calendar, after, before, os.path.join(base_path, '../template/calendar.json')) |