From f21bb4d65c8d0589c2cfd382310f878337fac4bb Mon Sep 17 00:00:00 2001 From: Joan Cano Date: Thu, 2 Mar 2023 11:58:14 +0100 Subject: [PATCH] =?UTF-8?q?Otro=20intento=20m=C3=A1s=20para=20escapar=20ca?= =?UTF-8?q?racteres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wallamanta/helpers.py | 1 + wallamanta/worker.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wallamanta/helpers.py b/wallamanta/helpers.py index 580132c..f4e89eb 100644 --- a/wallamanta/helpers.py +++ b/wallamanta/helpers.py @@ -1,3 +1,4 @@ +#TELEGRAM_ESCAPE_CHARACTERS = ['_', '*', '[', ']', '(', ')', '~', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'] TELEGRAM_ESCAPE_CHARACTERS = ['_', '*', '[', ']', '(', ')', '~', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'] def telegram_escape_characters(text): diff --git a/wallamanta/worker.py b/wallamanta/worker.py index 9ad4a48..4437bb6 100644 --- a/wallamanta/worker.py +++ b/wallamanta/worker.py @@ -76,13 +76,13 @@ class Worker: try: if not self.has_excluded_words(article['title'].lower(), article['description'].lower(), product['exclude']) and not self.is_title_key_word_excluded(article['title'].lower(), product['title_keyword_exclude']): try: - text = f"*Artículo*: {article['title']}\n*Descripción*: {article['description']}\n*Precio*: {article['price']} {article['currency']}\n[Ir al anuncio](https://es.wallapop.com/item/{article['web_slug']})".replace(".", "\.") - url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage?chat_id={TELEGRAM_CHANNEL_ID}&text={helpers.telegram_escape_characters(text)}&parse_mode=MarkdownV2" + text = f"*Artículo*: {helpers.telegram_escape_characters(article['title'])}\n*Descripción*: {helpers.telegram_escape_characters(article['description'])}\n*Precio*: {helpers.telegram_escape_characters(article['price'])} {helpers.telegram_escape_characters(article['currency'])}\n[Ir al anuncio](https://es.wallapop.com/item/{helpers.telegram_escape_characters(article['web_slug'])})" + url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage?chat_id={TELEGRAM_CHANNEL_ID}&text={text}&parse_mode=MarkdownV2" logging.info(requests.get(url).json()) except: - text = f"*Artículo*: {article['title']}\n*Descripción*: {article['description']}\n*Precio*: {article['price']} {article['currency']}\n[Ir al anuncio](https://es.wallapop.com/item/{article['web_slug']})".replace(".", "\.") - url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage?chat_id={TELEGRAM_CHANNEL_ID}&text={helpers.telegram_escape_characters(text)}&parse_mode=MarkdownV2" - requests.get(url) + text = f"*Artículo*: {helpers.telegram_escape_characters(article['title'])}\n*Descripción*: {helpers.telegram_escape_characters(article['description'])}\n*Precio*: {helpers.telegram_escape_characters(article['price'])} {helpers.telegram_escape_characters(article['currency'])}\n[Ir al anuncio](https://es.wallapop.com/item/{helpers.telegram_escape_characters(article['web_slug'])})" + url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage?chat_id={TELEGRAM_CHANNEL_ID}&text={text}&parse_mode=MarkdownV2" + logging.info(requests.get(url).json()) time.sleep(1) # Avoid Telegram flood restriction list.insert(0, article['id']) except Exception as e: