diff options
-rw-r--r-- | scripts/get_calendar.py | 16 |
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')) |