Added NR logging for found products
This commit is contained in:
@@ -18,6 +18,8 @@ services:
|
||||
- DB_NAME=${DB_NAME}
|
||||
- DB_USER=${DB_USER}
|
||||
- DB_PASSWORD=${DB_PASSWORD}
|
||||
- NEW_RELIC_INSERT_KEY=${NEW_RELIC_INSERT_KEY}
|
||||
- NR_ENV=${NR_ENV}
|
||||
|
||||
wallamanta_db:
|
||||
image: mysql:8
|
||||
|
||||
@@ -13,6 +13,10 @@ DB_NAME = os.getenv("DB_NAME")
|
||||
LATITUDE = os.getenv("LATITUDE")
|
||||
LONGITUDE = os.getenv("LONGITUDE")
|
||||
SLEEP_TIME = int(os.getenv("SLEEP_TIME"))
|
||||
NEW_RELIC_INSERT_KEY = os.getenv("NEW_RELIC_INSERT_KEY")
|
||||
NR_ENV = os.getenv("NR_ENV")
|
||||
|
||||
|
||||
|
||||
CATEGORIES = {
|
||||
100: ["🚗 Coches 🚗"],
|
||||
|
||||
@@ -5,6 +5,7 @@ import logging
|
||||
import constants
|
||||
import pytz
|
||||
import walladb
|
||||
from newrelic_telemetry_sdk import Event, EventClient
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from datetime import datetime, timedelta, timezone, date
|
||||
@@ -138,6 +139,7 @@ async def send_article(article, product):
|
||||
markup = InlineKeyboardMarkup(keyboard)
|
||||
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)
|
||||
send_to_nr(article, product)
|
||||
logging.info(response)
|
||||
|
||||
def get_category_name(category):
|
||||
@@ -271,4 +273,24 @@ def get_thread(product_name):
|
||||
for product_thread in SEARCH_THREADS_LIST:
|
||||
if product_name == product_thread[0]:
|
||||
return product_thread[1]
|
||||
return None
|
||||
return None
|
||||
|
||||
def send_to_nr(article, product):
|
||||
event = Event(
|
||||
"ProductFound", {
|
||||
"article_name": article['title'],
|
||||
"article_price": article['price'],
|
||||
"article_web_slug": article['web_slug'],
|
||||
"product_name": product['product_name'],
|
||||
"telegram_user_id": product['telegram_user_id'],
|
||||
"telegram_user_name": product['telegram_user_name'],
|
||||
"environment": constants.NR_ENV
|
||||
}
|
||||
)
|
||||
event_client = EventClient(insert_key=constants.NEW_RELIC_INSERT_KEY, host="insights-collector.eu01.nr-data.net")
|
||||
try:
|
||||
response = event_client.send(event)
|
||||
except Exception as e:
|
||||
logging.error(f"Error sending to NR: {e}")
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@ python-telegram-bot[job-queue]==20.1
|
||||
requests==2.28.1
|
||||
prettytable==3.6.0
|
||||
Pillow==9.4.0
|
||||
mysql-connector-python==8.0.32
|
||||
mysql-connector-python==8.0.32
|
||||
newrelic-telemetry-sdk==0.4.3
|
||||
@@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
|
||||
class Worker:
|
||||
|
||||
_stop = False
|
||||
|
||||
|
||||
def is_valid_request(self, product):
|
||||
is_valid = False
|
||||
if walladb.get_product(product):
|
||||
|
||||
Reference in New Issue
Block a user