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
|
from django.db.models import Count
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
|
from .logger import get_logger
|
||||||
|
logger = get_logger()
|
||||||
|
|
||||||
def notify_telegram_info(last_hours, channel="INFO"):
|
def notify_telegram_info(last_hours, channel="INFO"):
|
||||||
|
try:
|
||||||
start_date = timezone.now() - timedelta(hours=last_hours)
|
start_date = timezone.now() - timedelta(hours=last_hours)
|
||||||
|
|
||||||
# Count the number of URLs grouped by status within the date range
|
# 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
|
# POST
|
||||||
response = requests.post(url, params=params)
|
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"):
|
def notify_telegram_warning(last_hours, channel="WARNING"):
|
||||||
|
try:
|
||||||
# Message appending logic
|
# Message appending logic
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
@@ -135,6 +141,8 @@ def notify_telegram_warning(last_hours, channel="WARNING"):
|
|||||||
|
|
||||||
# POST
|
# POST
|
||||||
response = requests.post(url, params=params)
|
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):
|
def notify_telegram(last_hours=12):
|
||||||
|
|||||||
Reference in New Issue
Block a user