From cde836a9aead1d9a5161b6f3c4155f97d803ca43 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Tue, 5 Apr 2016 14:15:03 -0300 Subject: Generate other event json for tabular calendar --- .gitignore | 1 + scripts/get_calendar.py | 38 +++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index d202ce7..7759601 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /public/api *~ /template/calendar.json +/template/tabcalendar.json diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py index 948db0e..639e1ea 100644 --- a/scripts/get_calendar.py +++ b/scripts/get_calendar.py @@ -71,22 +71,12 @@ class DatetimeEncoder(json.JSONEncoder): return obj.isoformat() return json.JSONEncoder.default(self,obj) -#CALENDARIUM_IMPORT_URL = 'https://sublab.org:5232/calendars/events' -CALENDARIUM_IMPORT_URL = 'https://posteo.de/calendars/ics/ruku1tibpa2b2evfwsxrbvwcy2n60j9g' -if __name__ == '__main__': - logging.basicConfig(stream=sys.stderr, level=logging.ERROR) - logger = logging.getLogger('calendar_feed') - calendar = fetch_calendar(logger) - now = datetime.now() - after = now - relativedelta(days=1) - before = now + relativedelta(months=+1) - +def put_events(calendar, after, before, destination): events = [] for event in get_events(calendar, after, before): event['start'] = event['start'].isoformat() event['end'] = event['end'].isoformat() events.append(event) - destination = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../template/calendar.json') if os.path.exists(destination): with open(destination, 'r') as dfile: current = dfile.read() @@ -98,4 +88,30 @@ if __name__ == '__main__': with open(destination + '.new', 'w') as dfile: dfile.write(output) os.rename(destination + '.new', destination) + return True + return False + +#CALENDARIUM_IMPORT_URL = 'https://sublab.org:5232/calendars/events' +CALENDARIUM_IMPORT_URL = 'https://posteo.de/calendars/ics/ruku1tibpa2b2evfwsxrbvwcy2n60j9g' +if __name__ == '__main__': + logging.basicConfig(stream=sys.stderr, level=logging.ERROR) + logger = logging.getLogger('calendar_feed') + calendar = fetch_calendar(logger) + now = datetime.now() + after = now - relativedelta(days=1) + before = now + relativedelta(months=+1) + base_path = os.path.dirname(os.path.abspath(__file__)) + + after_tab = datetime(now.year,now.month,1); + if now.month + 2 > 12: + before_tab = datetime(now.year+1,now.month + 10,1) + else: + before_tab = datetime(now.year,now.month+2,1) + + changed = put_events(calendar, after, before, + os.path.join(base_path, '../template/calendar.json')) + tab_changed = put_events(calendar, after_tab, before_tab, + os.path.join(base_path, '../template/tabcalendar.json')) + + if changed or tab_changed: subprocess.call(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template.py')) -- cgit v1.2.1