diff --git a/bot/dbhelper.py b/bot/dbhelper.py index 7678999..f0e1b72 100644 --- a/bot/dbhelper.py +++ b/bot/dbhelper.py @@ -21,10 +21,13 @@ def add_product(tg_user, tg_group, tg_user_id, tg_group_id, url, referurl, title con.commit() con.close() - response = requests.get(image, headers=constants.HEADERS) - file = open(f"/app/data/images/products/{product_id}.jpg", "wb") - file.write(response.content) - file.close() + try: + response = requests.get(image, headers=constants.HEADERS) + file = open(f"/app/data/images/products/{product_id}.jpg", "wb") + file.write(response.content) + file.close() + except: + pass return product_id diff --git a/bot/helpers.py b/bot/helpers.py index 20172b6..d58e98e 100644 --- a/bot/helpers.py +++ b/bot/helpers.py @@ -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.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 - 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])) wsize = int((float(product_image.size[0]) * float(hpercent))) if wsize < wlimit: diff --git a/data/images/placeholder.png b/data/images/placeholder.png new file mode 100644 index 0000000..fe74514 Binary files /dev/null and b/data/images/placeholder.png differ