Added image placeholder if cant retrieve it
This commit is contained in:
@@ -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()
|
||||||
|
|
||||||
|
try:
|
||||||
response = requests.get(image, headers=constants.HEADERS)
|
response = requests.get(image, headers=constants.HEADERS)
|
||||||
file = open(f"/app/data/images/products/{product_id}.jpg", "wb")
|
file = open(f"/app/data/images/products/{product_id}.jpg", "wb")
|
||||||
file.write(response.content)
|
file.write(response.content)
|
||||||
file.close()
|
file.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return product_id
|
return product_id
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
try:
|
||||||
product_image = Image.open(f"/app/data/images/products/{product_id}.jpg")
|
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
BIN
data/images/placeholder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user