summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get_calendar.py38
1 files changed, 27 insertions, 11 deletions
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'))