diff --git a/wallamanta/helpers.py b/wallamanta/helpers.py index 9f36b11..8bda1e6 100644 --- a/wallamanta/helpers.py +++ b/wallamanta/helpers.py @@ -122,6 +122,8 @@ def create_image(article): image.paste(product_image, (int((width/3)-(product_image.size[0]/2)), int((height/2) - (product_image.size[1]/2)))) # guardamos la imagen con otro nombre image.save(f"/app/data/images/products/{article['id']}_composed.png", quality=95) + image.close() + product_image.close() def get_publish_date(article): article_date = article['creation_date'] @@ -166,15 +168,17 @@ def send_article(article, product): #markup = InlineKeyboardMarkup(keyboard) keyboard = {'inline_keyboard':[[{'text':'Ir al anuncio','url':f'https://es.wallapop.com/item/{article["web_slug"]}'}]]} + image = open(f"/app/data/images/products/{article['id']}_composed.png", 'rb') files = { 'chat_id': (None, product['telegram_user_id']), - 'photo': open(f"/app/data/images/products/{article['id']}_composed.png", 'rb'), + 'photo': image, 'caption': (None, text), 'parse_mode': (None, ParseMode.MARKDOWN_V2), 'reply_markup': (None, keyboard), } response = requests.post(f'https://api.telegram.org/bot{constants.TELEGRAM_TOKEN}/sendPhoto', files=files) + image.close() #response = await application.bot.send_photo(chat_id=product['telegram_user_id'], photo=open(f"/app/data/images/products/{article['id']}_composed.png", 'rb'), caption=text, parse_mode=ParseMode.MARKDOWN_V2, reply_markup=markup) #logging.info(requests.post(url, files=files).content)