From c8e25c29ef38cc0d38c0dd53846dad0873d72ec8 Mon Sep 17 00:00:00 2001 From: rra Date: Fri, 9 Sep 2022 14:23:00 +0200 Subject: [PATCH] do proper handling of file paths --- event_feed.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/event_feed.py b/event_feed.py index d11fb1c..d20c7a2 100644 --- a/event_feed.py +++ b/event_feed.py @@ -130,8 +130,8 @@ def create_event_post(post_dir, event): for img in event_metadata['images']: #parse img url to safe local image name - img_name = img.split('/')[-1] - fn, ext = img_name.split('.') + img_name = os.path.basename(img) + fn, ext = os.path.splitext(img_name) img_name = slugify(fn) + '.' + ext local_image = os.path.join(post_dir, img_name) @@ -142,6 +142,7 @@ def create_event_post(post_dir, event): with open(local_image, 'wb') as img_file: shutil.copyfileobj(response.raw, img_file) print('Downloaded image for event "{}"'.format(event.name)) + # TODO fix bug here event_metadata['description'] = event_metadata['description'].replace(img, '![]({})'.format(img_name)) if img_name in existing_images: existing_images.remove(img_name)