summaryrefslogtreecommitdiff
path: root/scripts/get_calendar.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/get_calendar.py')
-rw-r--r--scripts/get_calendar.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py
index 8db09c9..89daf07 100644
--- a/scripts/get_calendar.py
+++ b/scripts/get_calendar.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta, time
+from datetime import datetime, timedelta, time, date
from dateutil.relativedelta import relativedelta
import urllib2
@@ -34,7 +34,21 @@ def fetch_calendar(logger):
export_file.write(content)
os.rename(CALENDARIUM_EXPORT + '.new', CALENDARIUM_EXPORT)
- return icalendar.Calendar.from_ical(content)
+ try:
+ with open(TODAY_EXPORT, 'r') as today_file:
+ cached_today = today_file.read()
+ except Exception:
+ cached_today = None
+
+ real_today = str(date.today()) + '\n'
+ if real_today != cached_today:
+ with open(TODAY_EXPORT, 'w') as today_file:
+ today_file.write(real_today)
+ regen = True
+ else:
+ regen = False
+
+ return (regen,icalendar.Calendar.from_ical(content))
def get_events(calendar, after, before):
"""Yields all events in calendar as dictionary.
@@ -112,11 +126,11 @@ base_path = os.path.dirname(os.path.abspath(__file__))
#CALENDARIUM_IMPORT_URL = 'https://sublab.org:5232/calendars/events'
CALENDARIUM_IMPORT_URL = 'https://posteo.de/calendars/ics/ruku1tibpa2b2evfwsxrbvwcy2n60j9g'
CALENDARIUM_EXPORT = os.path.join(base_path, '../public/calendar.ics')
-
+TODAY_EXPORT = os.path.join(base_path, 'get_calendar.today')
if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr, level=logging.ERROR)
logger = logging.getLogger('calendar_feed')
- calendar = fetch_calendar(logger)
+ regen, calendar = fetch_calendar(logger)
now = datetime.now()
after = now - relativedelta(days=1)
before = now + relativedelta(months=+1)
@@ -132,5 +146,5 @@ if __name__ == '__main__':
tab_changed = put_events(calendar, after_tab, before_tab,
os.path.join(base_path, '../template/tabcalendar.json'))
- if changed or tab_changed:
+ if changed or tab_changed or regen:
subprocess.call(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template.py'))