diff options
author | Christian Franke <nobody@nowhere.ws> | 2016-04-05 14:15:03 -0300 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2016-04-05 14:15:48 -0300 |
commit | cde836a9aead1d9a5161b6f3c4155f97d803ca43 (patch) | |
tree | 02ef49336fd894bce86e83ce424a15a01fc0b184 | |
parent | 40319cc20912adab578c88d5463ba70c70add48f (diff) |
Generate other event json for tabular calendar
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | scripts/get_calendar.py | 38 |
2 files changed, 28 insertions, 11 deletions
@@ -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')) |