View fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from .views_base import link_list, logs, log_db #, trigger_task,
|
from .views_base import link_list, logs, log_db, notify_status #, 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
|
||||||
@@ -9,8 +9,7 @@ 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
|
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
@@ -145,46 +144,6 @@ 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):
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
from django.http import JsonResponse, HttpResponse
|
from django.http import JsonResponse, HttpResponse
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.utils.timezone import now, timedelta
|
||||||
|
from .models import Urls, Source, Search, UrlContent, UrlsSourceSearch, UrlsDuplicate
|
||||||
|
from django.db.models import Q, Count
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
"""
|
"""
|
||||||
@@ -72,3 +78,45 @@ def log_db(request):
|
|||||||
return HttpResponse( "\n".join([str(e) for e in r]) )
|
return HttpResponse( "\n".join([str(e) for e in r]) )
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
return HttpResponse( "\n".join([str(e) for e in message]) )
|
||||||
Reference in New Issue
Block a user