From 0b9ab40ac0af56a912861336655bc415f977d6a1 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 9 Apr 2024 10:50:40 +0200 Subject: [PATCH] Don't store images anymore --- wallamanta/helpers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wallamanta/helpers.py b/wallamanta/helpers.py index a9d61e0..7e936fe 100644 --- a/wallamanta/helpers.py +++ b/wallamanta/helpers.py @@ -7,6 +7,7 @@ import pytz import walladb import json import string +import os from newrelic_telemetry_sdk import Event, EventClient, GaugeMetric, MetricClient from PIL import Image, ImageDraw, ImageFont @@ -109,6 +110,18 @@ def create_image(article, product_id): # guardamos la imagen con otro nombre image.save(f"/app/data/images/products/{article['id']}_{product_id}_composed.png", quality=95) +def remove_image(article, product_id): + image_path = f"/app/data/images/products/{article['id']}_{product_id}.jpg" + composed_image_path = f"/app/data/images/products/{article['id']}_{product_id}_composed.png" + if os.path.exists(image_path): + os.remove(image_path) + else: + logging.info(f"Tried to delete {article} image. Couldn't find it.") + if os.path.exists(composed_image_path): + os.remove(composed_image_path) + else: + logging.info(f"Tried to delete {article} image. Couldn't find it.") + def get_publish_date(article): article_date = article['creation_date'] formato_fecha = "%Y-%m-%dT%H:%M:%S.%f%z" @@ -207,6 +220,7 @@ def send_article(article, product): #logging.info(requests.post(url, files=files).content) send_to_nr(article, product) #logging.info(response.content) + remove_image(article, product['id']) logging.info(f"'{title}' (https://es.wallapop.com/item/{article['web_slug']}) found by {product['product_name']} ({product['id']}) - ({walladb.get_user(product['telegram_user_id'])})") def get_category_name(category):