From fc0685fb0dfec3bc470175baf8d9398ddfc21195 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 4 Jul 2023 14:31:19 +0200 Subject: [PATCH] Added more info to message, location, shipping status... --- wallamanta/helpers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wallamanta/helpers.py b/wallamanta/helpers.py index ad19f31..3b92610 100644 --- a/wallamanta/helpers.py +++ b/wallamanta/helpers.py @@ -123,6 +123,10 @@ def get_publish_date(article): article_date = article['creation_date'] return datetime.fromtimestamp(int(int(article_date)/1000)).astimezone(pytz.timezone("Europe/Madrid")).strftime("%d/%m/%Y - %H:%M:%S") +def get_modified_date(article): + article_date = article['modification_date'] + return datetime.fromtimestamp(int(int(article_date)/1000)).astimezone(pytz.timezone("Europe/Madrid")).strftime("%d/%m/%Y - %H:%M:%S") + async def send_article(article, product): application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build() create_image(article) @@ -130,12 +134,18 @@ async def send_article(article, product): description = f"*📝 Descripción*: {telegram_escape_characters(article['description'])}" found_by = f"*🔍 Encontrado por la búsqueda de:* {telegram_escape_characters(product['product_name'])}" created_at = f"*📅 Fecha de publicación:* {telegram_escape_characters(get_publish_date(article))}" + modified_at = f"*📅 Fecha de modificación:* {telegram_escape_characters(get_modified_date(article))}" + location = f"📍 *Lugar:* {telegram_escape_characters(article['location']['city'])} ({telegram_escape_characters(article['location']['postal_code']) - {telegram_escape_characters(article['location']['country_code'])}})" + if article['shipping']['user_allows_shipping']: + user_ships = f"📦 *Envío:* ✅" + else: + user_ships = f"📦 *Envío:* ❌" if article['currency'] == 'EUR': currency = '€' else: currency = '?' price = f"*💰 Precio*: {telegram_escape_characters(str(article['price']))} {telegram_escape_characters(currency)}" - text = f"{title}\n\n{description}\n\n{found_by}\n\n{created_at}\n\n{price}" + text = f"{title}\n\n{description}\n\n{found_by}\n\n{created_at}\n{modified_at}\n\n{location}\n\n{user_ships}\n\n{price}" #url = f"https://api.telegram.org/bot{constants.TELEGRAM_TOKEN}/sendPhoto?chat_id={product['telegram_user_id']}&caption={text}&parse_mode=MarkdownV2" #files = {'photo':open(f"/app/data/images/products/{article['id']}_composed.png", 'rb')} keyboard = [[InlineKeyboardButton("Ir al anuncio", url=f"https://es.wallapop.com/item/{article['web_slug']}")]] @@ -287,7 +297,8 @@ def send_to_nr(article, product): "article_web_slug": article['web_slug'], "product_name": product['product_name'], "telegram_user_id": product['telegram_user_id'], - "telegram_name": walladb.get_user(product['telegram_user_id']), + "telegram_name": walladb.get_user(product['telegram_user_id']), + "seller_id": article['seller_id'], "environment": constants.NR_ENV } )