Extracted main functionality into extra function

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
2018-07-18 14:49:02 +02:00
parent 4e8c0a74aa
commit bd51cc6d50

View File

@ -43,7 +43,17 @@ def main() -> None:
if not isdir(args.event_collection_path): if not isdir(args.event_collection_path):
raise ValueError('event_collection_path: The given event collection path is not a directory.') 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( template_filename = pkg_resources.resource_filename(
__package__, __package__,
'event_template.markdown' 'event_template.markdown'
@ -64,5 +74,5 @@ def main() -> None:
event_content = event_content.replace('<location>', event.location) event_content = event_content.replace('<location>', event.location)
event_filename = begin.date().isoformat() + '-' + event.name.replace(' ', '_') + '.markdown' 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) event_file.write(event_content)