Don't store images anymore

This commit is contained in:
Joan
2024-04-09 10:50:40 +02:00
parent be909fc937
commit 0b9ab40ac0

View File

@@ -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):