Added image placeholder if cant retrieve it

This commit is contained in:
Joan
2023-06-28 13:26:31 +02:00
parent a40f55ca4e
commit 243d0ba749
3 changed files with 11 additions and 5 deletions

View File

@@ -21,10 +21,13 @@ def add_product(tg_user, tg_group, tg_user_id, tg_group_id, url, referurl, title
con.commit() con.commit()
con.close() con.close()
response = requests.get(image, headers=constants.HEADERS) try:
file = open(f"/app/data/images/products/{product_id}.jpg", "wb") response = requests.get(image, headers=constants.HEADERS)
file.write(response.content) file = open(f"/app/data/images/products/{product_id}.jpg", "wb")
file.close() file.write(response.content)
file.close()
except:
pass
return product_id return product_id

View File

@@ -40,7 +40,10 @@ def create_image(product_id, price):
draw.text(((width / 6) * 5 - wtext / 2, height / 2 - htext / 2), price, (0, 0, 0), font=font) draw.text(((width / 6) * 5 - wtext / 2, height / 2 - htext / 2), price, (0, 0, 0), font=font)
draw.rectangle([15, 15, width - 15, height - 15], width = 15, outline="#20e163") draw.rectangle([15, 15, width - 15, height - 15], width = 15, outline="#20e163")
# ponemos la imagen del producto en la parte izquierda y se redimensiona dependiendo de lo ancho # ponemos la imagen del producto en la parte izquierda y se redimensiona dependiendo de lo ancho
product_image = Image.open(f"/app/data/images/products/{product_id}.jpg") try:
product_image = Image.open(f"/app/data/images/products/{product_id}.jpg")
except:
product_image = Image.open(f"/app/data/images/placeholder.jpg")
hpercent = (baseheight / float(product_image.size[1])) hpercent = (baseheight / float(product_image.size[1]))
wsize = int((float(product_image.size[0]) * float(hpercent))) wsize = int((float(product_image.size[0]) * float(hpercent)))
if wsize < wlimit: if wsize < wlimit:

BIN
data/images/placeholder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB