cal: check if image exists before downloading

This commit is contained in:
knoflook 2022-02-03 12:34:24 +01:00 committed by Gitea
parent 1fe2fa3bcf
commit 3297991d83
1 changed files with 7 additions and 6 deletions

View File

@ -146,12 +146,13 @@ def create_event_post(post_dir, event):
if not os.path.exists(local_image):
# download preview image
response = requests.get(img, stream=True)
with open(local_image, "wb") as img_file:
shutil.copyfileobj(response.raw, img_file)
print('Downloaded image for event "{}"'.format(event.name))
event_metadata["description"] = event_metadata["description"].replace(
img, "![]({})".format(img_name)
)
if response.status_code == 200:
with open(local_image, "wb") as img_file:
shutil.copyfileobj(response.raw, img_file)
print('Downloaded image for event "{}"'.format(event.name))
event_metadata["description"] = event_metadata["description"].replace(
img, "![]({})".format(img_name)
)
if img_name in existing_images:
existing_images.remove(img_name)