Added more info to message, location, shipping status...

This commit is contained in:
Joan
2023-07-04 14:31:19 +02:00
parent 5d9e2d1961
commit fc0685fb0d

View File

@@ -123,6 +123,10 @@ def get_publish_date(article):
article_date = article['creation_date'] 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") 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): async def send_article(article, product):
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build() application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build()
create_image(article) create_image(article)
@@ -130,12 +134,18 @@ async def send_article(article, product):
description = f"*📝 Descripción*: {telegram_escape_characters(article['description'])}" description = f"*📝 Descripción*: {telegram_escape_characters(article['description'])}"
found_by = f"*🔍 Encontrado por la búsqueda de:* {telegram_escape_characters(product['product_name'])}" 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))}" 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': if article['currency'] == 'EUR':
currency = '' currency = ''
else: else:
currency = '?' currency = '?'
price = f"*💰 Precio*: {telegram_escape_characters(str(article['price']))} {telegram_escape_characters(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" #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')} #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']}")]] keyboard = [[InlineKeyboardButton("Ir al anuncio", url=f"https://es.wallapop.com/item/{article['web_slug']}")]]
@@ -288,6 +298,7 @@ def send_to_nr(article, product):
"product_name": product['product_name'], "product_name": product['product_name'],
"telegram_user_id": product['telegram_user_id'], "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 "environment": constants.NR_ENV
} }
) )