From 69f0ab5661ef426d0b010f41ca5d7201a032c1bc Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 18 Jul 2018 17:21:11 +0200 Subject: [PATCH] Added support for removing events in calendar Signed-off-by: Jim Martens --- CHANGES.txt | 2 ++ src/twomartens/calendarsync/calendarsync.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 0477b3a..c532da0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,8 @@ 1.0.2 ----- +* added support for removing events in the calendar + (achieved by deleting all event files prior to creating them) * added changes.txt file (including changes for 1.0.1) 1.0.1 diff --git a/src/twomartens/calendarsync/calendarsync.py b/src/twomartens/calendarsync/calendarsync.py index f912432..e2db05e 100644 --- a/src/twomartens/calendarsync/calendarsync.py +++ b/src/twomartens/calendarsync/calendarsync.py @@ -17,6 +17,8 @@ """calendarsync.calendarsync: provides entry point main()""" import argparse import datetime +import glob +import os from os.path import isdir import pkg_resources @@ -53,6 +55,12 @@ def sync(calendar_url: str, event_collection_path: str) -> None: ) with open(template_filename, 'r', encoding='utf-8') as template: template_content = template.read() + + # remove previous event files in directory to allow the removal of events in calendar + files = glob.glob(event_collection_path + '*.markdown') + for file in files: + os.remove(file) + for event in calendar.events: event_content = template_content.replace('', event.name) created: datetime.datetime = event.created