From bd51cc6d50631fecf08b74bc102f0f6c3aa3da1b Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 18 Jul 2018 14:49:02 +0200 Subject: [PATCH] Extracted main functionality into extra function Signed-off-by: Jim Martens --- src/twomartens/calendarsync/calendarsync.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/twomartens/calendarsync/calendarsync.py b/src/twomartens/calendarsync/calendarsync.py index 60b6a03..e2e8e8a 100644 --- a/src/twomartens/calendarsync/calendarsync.py +++ b/src/twomartens/calendarsync/calendarsync.py @@ -43,7 +43,17 @@ def main() -> None: if not isdir(args.event_collection_path): raise ValueError('event_collection_path: The given event collection path is not a directory.') - calendar = Calendar(urlopen(args.calendar_url).read().decode('utf-8')) + sync(args.calendar_url, args.event_collection_path) + + +def sync(calendar_url: str, event_collection_path: str) -> None: + """ + Synchronizes the event collection with a remote calendar. + + :param calendar_url: URL to remote calendar ICS + :param event_collection_path: path to event collection directory + """ + calendar = Calendar(urlopen(calendar_url).read().decode('utf-8')) template_filename = pkg_resources.resource_filename( __package__, 'event_template.markdown' @@ -62,7 +72,7 @@ def main() -> None: end_str = end.isoformat(sep=' ') event_content = event_content.replace('', end_str) event_content = event_content.replace('', event.location) - + event_filename = begin.date().isoformat() + '-' + event.name.replace(' ', '_') + '.markdown' - with open(args.event_collection_path + event_filename, 'w', encoding='utf-8', newline='\n') as event_file: + with open(event_collection_path + event_filename, 'w', encoding='utf-8', newline='\n') as event_file: event_file.write(event_content)