Notifications, info and warning, try catch

This commit is contained in:
Luciano Gervasoni
2025-09-09 22:06:23 +02:00
parent 24510d26e2
commit f44b784715

View File

@@ -4,8 +4,11 @@ from ..models import Urls, Source, Search, UrlContent, UrlsSourceSearch, UrlsDup
from django.db.models import Count
import requests
import os
from .logger import get_logger
logger = get_logger()
def notify_telegram_info(last_hours, channel="INFO"):
try:
start_date = timezone.now() - timedelta(hours=last_hours)
# Count the number of URLs grouped by status within the date range
@@ -53,9 +56,12 @@ def notify_telegram_info(last_hours, channel="INFO"):
# POST
response = requests.post(url, params=params)
except Exception as e:
logger.info("Exception while notifying status: {}".format(str(e)))
def notify_telegram_warning(last_hours, channel="WARNING"):
try:
# Message appending logic
message = ""
@@ -135,6 +141,8 @@ def notify_telegram_warning(last_hours, channel="WARNING"):
# POST
response = requests.post(url, params=params)
except Exception as e:
logger.info("Exception while notifying status: {}".format(str(e)))
def notify_telegram(last_hours=12):