Notify status
This commit is contained in:
@@ -4,6 +4,7 @@ from . import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.link_list, name='link_list'),
|
path('', views.link_list, name='link_list'),
|
||||||
#
|
#
|
||||||
|
path('notify_status', views.notify_status, name='notify_status'),
|
||||||
path('logs/database', views.log_db, name='log_db'),
|
path('logs/database', views.log_db, name='log_db'),
|
||||||
path('logs/<str:log_type>', views.logs, name='logs'),
|
path('logs/<str:log_type>', views.logs, name='logs'),
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ from .views_base import link_list, logs, log_db #, trigger_task,
|
|||||||
|
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.http import StreamingHttpResponse, JsonResponse, HttpResponse
|
from django.http import StreamingHttpResponse, JsonResponse
|
||||||
from django.db.models import Q, Count
|
from django.db.models import Q, Count
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.timezone import now, timedelta
|
from django.utils.timezone import now, timedelta
|
||||||
from .models import Urls, Source, Search, UrlContent, UrlsSourceSearch, UrlsDuplicate
|
from .models import Urls, Source, Search, UrlContent, UrlsSourceSearch, UrlsDuplicate
|
||||||
from .src.llm import OllamaClient
|
from .src.llm import OllamaClient
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
@@ -144,6 +145,46 @@ def urls_per_search(request):
|
|||||||
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
def notify_status(request):
|
||||||
|
last_hours = 24
|
||||||
|
start_date = timezone.now() - timedelta(hours=last_hours)
|
||||||
|
|
||||||
|
# Count the number of URLs grouped by status within the date range
|
||||||
|
urls_data_status = Urls.objects.filter(ts_fetch__gte=start_date) \
|
||||||
|
.values('status') \
|
||||||
|
.annotate(count=Count('id')) \
|
||||||
|
.order_by('status')
|
||||||
|
|
||||||
|
# Count the number of URLs grouped by source
|
||||||
|
urls_data_source = UrlsSourceSearch.objects \
|
||||||
|
.filter(id_url__ts_fetch__gte=start_date) \
|
||||||
|
.values('id_source__source') \
|
||||||
|
.annotate(count=Count('id_url')) \
|
||||||
|
.order_by('id_source__source')
|
||||||
|
|
||||||
|
# Count the number of URLs grouped by search
|
||||||
|
urls_data_search = UrlsSourceSearch.objects \
|
||||||
|
.filter(id_url__ts_fetch__gte=start_date) \
|
||||||
|
.values('id_search__search') \
|
||||||
|
.annotate(count=Count('id_url')) \
|
||||||
|
.order_by('id_search__search')
|
||||||
|
|
||||||
|
|
||||||
|
bot_token = os.getenv("TELEGRAM_BOT_TOKEN", "")
|
||||||
|
chat_id = os.getenv("TELEGRAM_CHAT_ID", "")
|
||||||
|
|
||||||
|
message = "During the last {} hours:\n{}\n{}\n{}".format(last_hours, urls_data_status, urls_data_source, urls_data_search)
|
||||||
|
|
||||||
|
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
|
||||||
|
params = {
|
||||||
|
"chat_id": chat_id,
|
||||||
|
"text": message
|
||||||
|
}
|
||||||
|
|
||||||
|
# POST
|
||||||
|
response = requests.post(url, params=params)
|
||||||
|
# print(response.json()) # Check the response
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
def filtered_urls(request):
|
def filtered_urls(request):
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def link_list(request):
|
|||||||
links_process = ["process_raw_urls_50", "process_error_urls_50", "process_missing_kids_urls_50", "process_missing_kids_urls_valid_all", "process_missing_kids_urls_invalid_all", "process_missing_kids_urls_unknown_all", "process_missing_kids_urls_all", "clean_old_url_content_60"]
|
links_process = ["process_raw_urls_50", "process_error_urls_50", "process_missing_kids_urls_50", "process_missing_kids_urls_valid_all", "process_missing_kids_urls_invalid_all", "process_missing_kids_urls_unknown_all", "process_missing_kids_urls_all", "clean_old_url_content_60"]
|
||||||
# List of links
|
# List of links
|
||||||
list_links = \
|
list_links = \
|
||||||
[ os.path.join(app_url, "admin"), os.path.join(app_url, "urls") ] + \
|
[ os.path.join(app_url, "admin"), os.path.join(app_url, "urls"), os.path.join(app_url, "notify_status") ] + \
|
||||||
[ os.path.join(app_url, "logs", log_type) for log_type in ["database", "debug", "info", "warning", "server", "beat", "worker_default", "worker_low"] ] #+ \
|
[ os.path.join(app_url, "logs", log_type) for log_type in ["database", "debug", "info", "warning", "server", "beat", "worker_default", "worker_low"] ] #+ \
|
||||||
#[ os.path.join(app_url, "task", l) for l in links_fetch + links_process ]
|
#[ os.path.join(app_url, "task", l) for l in links_fetch + links_process ]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user