Notifications, info and warning, try catch
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user