Extracted main functionality into extra function
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -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>', end_str)
|
||||
event_content = event_content.replace('<location>', 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)
|
||||
|
||||
Reference in New Issue
Block a user