summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2016-04-05 16:38:06 -0300
committerChristian Franke <nobody@nowhere.ws>2016-04-05 16:38:06 -0300
commit185917e03703b190ac5a7baf3b9dddbbb8b398a6 (patch)
tree48b934b6049ddec1fc8b9a3aff0c113256d3495f
parent24ba2ff2b0d09dcfba560f7d29e76ef4ce6cc4bb (diff)
Mirror the iCal file
-rw-r--r--scripts/get_calendar.py27
-rw-r--r--template/pages/termine2/content.html6
2 files changed, 28 insertions, 5 deletions
diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py
index 639e1ea..cb3c800 100644
--- a/scripts/get_calendar.py
+++ b/scripts/get_calendar.py
@@ -15,9 +15,26 @@ import subprocess
def fetch_calendar(logger):
"""Fetches the calendar events and returns a icalendar.Calendar instance.
"""
- response = urllib2.urlopen(CALENDARIUM_IMPORT_URL)
- logger.debug('Fetched calendar from %s' % CALENDARIUM_IMPORT_URL)
- return icalendar.Calendar.from_ical(response.read())
+ try:
+ response = urllib2.urlopen(CALENDARIUM_IMPORT_URL)
+ logger.debug('Fetched calendar from %s' % CALENDARIUM_IMPORT_URL)
+ except Exception:
+ sys.excepthook(*sys.exc_info())
+ content = None
+ else:
+ content = response.read()
+
+ if content is None:
+ # If we couldn't fetch the content, pull it from the copied file
+ # if it's not there, just fail fatally as we don't have any data
+ with open(CALENDARIUM_EXPORT, 'r') as export_file:
+ content = export_file.read()
+ else:
+ with open(CALENDARIUM_EXPORT + '.new', 'w') as export_file:
+ export_file.write(content)
+ os.rename(CALENDARIUM_EXPORT + '.new', CALENDARIUM_EXPORT)
+
+ return icalendar.Calendar.from_ical(content)
def get_events(calendar, after, before):
"""Yields all events in calendar as dictionary.
@@ -91,8 +108,11 @@ def put_events(calendar, after, before, destination):
return True
return False
+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.ical')
+
if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr, level=logging.ERROR)
logger = logging.getLogger('calendar_feed')
@@ -100,7 +120,6 @@ if __name__ == '__main__':
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:
diff --git a/template/pages/termine2/content.html b/template/pages/termine2/content.html
index adb9f62..3e6c330 100644
--- a/template/pages/termine2/content.html
+++ b/template/pages/termine2/content.html
@@ -22,4 +22,8 @@ $tabcalendar_events
</p>
</div>
</div>
-
+<div class="row">
+<div class="col-md-12">
+<p>Ebenso gibt es einen <a href="/calendar.ical">iCAL Kalender</a> der die Veranstalungen enthaelt.</p>
+</div>
+</div>