Browse Source

do proper handling of file paths

master
rra 2 years ago
parent
commit
c8e25c29ef
  1. 5
      event_feed.py

5
event_feed.py

@ -130,8 +130,8 @@ def create_event_post(post_dir, event):
for img in event_metadata['images']: for img in event_metadata['images']:
#parse img url to safe local image name #parse img url to safe local image name
img_name = img.split('/')[-1] img_name = os.path.basename(img)
fn, ext = img_name.split('.') fn, ext = os.path.splitext(img_name)
img_name = slugify(fn) + '.' + ext img_name = slugify(fn) + '.' + ext
local_image = os.path.join(post_dir, img_name) 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: with open(local_image, 'wb') as img_file:
shutil.copyfileobj(response.raw, img_file) shutil.copyfileobj(response.raw, img_file)
print('Downloaded image for event "{}"'.format(event.name)) print('Downloaded image for event "{}"'.format(event.name))
# TODO fix bug here
event_metadata['description'] = event_metadata['description'].replace(img, '![]({})'.format(img_name)) event_metadata['description'] = event_metadata['description'].replace(img, '![]({})'.format(img_name))
if img_name in existing_images: if img_name in existing_images:
existing_images.remove(img_name) existing_images.remove(img_name)

Loading…
Cancel
Save