summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2016-01-18 18:19:23 +0100
committerChristian Franke <nobody@nowhere.ws>2016-01-18 18:20:12 +0100
commitfb426b903165e08a1de5372bdf5fdd20a3297882 (patch)
tree3e8ee45b8858cb6b2ad4e9b61c5ada15f73e8e47 /scripts
parent6ffcc8059b9d4466343c8c4e26b80f06738db437 (diff)
Rebuild webpage if calendar json changes
Diffstat (limited to 'scripts')
-rw-r--r--scripts/get_calendar.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py
index 3e0f8e3..8a59c93 100644
--- a/scripts/get_calendar.py
+++ b/scripts/get_calendar.py
@@ -10,6 +10,7 @@ import os
from dateutil.rrule import rrulestr
import icalendar
+import subprocess
def fetch_calendar(logger):
"""Fetches the calendar events and returns a icalendar.Calendar instance.
@@ -82,6 +83,15 @@ if __name__ == '__main__':
event['end'] = event['end'].isoformat()
events.append(event)
destination = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../template/calendar.json')
- with open(destination + '.new', 'w') as dfile:
- dfile.write(json.dumps(events, indent=4))
- os.rename(destination + '.new', destination)
+ if os.path.exists(destination):
+ with open(destination, 'r') as dfile:
+ current = dfile.read()
+ else:
+ current = None
+ output = json.dumps(events, indent=4)
+
+ if current != output:
+ with open(destination + '.new', 'w') as dfile:
+ dfile.write(output)
+ os.rename(destination + '.new', destination)
+ subprocess.call(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template.py'))