Обработка на ошибку

This commit is contained in:
zakhy 2025-01-15 09:48:58 +07:00
parent a5de6b9a23
commit bf6afc7430

View File

@ -137,25 +137,25 @@ def main_index(request):
def earthquake_list(request):
two_days_ago = datetime.datetime.now() - datetime.timedelta(days=2)
earthquakes = (Earthquake.objects.
filter(date_time__gt=two_days_ago).
order_by("-date_time").
all())
res = []
for earthquake in earthquakes:
# Формула для вычисления радиуса землетрясения
power = 0.5 * earthquake.magnitude - math.log10(earthquake.depth) - 1.2
radius = 10 ** power
res.append({
'id': earthquake.id,
'time': earthquake.date_time,
'lat': earthquake.latitude,
'lon': earthquake.longitude,
'depth': earthquake.depth,
'magnitude': earthquake.magnitude,
'region': earthquake.region,
'source': earthquake.source,
'radius': radius
})
return JsonResponse(res, safe=False)
try:
two_days_ago = datetime.datetime.now() - datetime.timedelta(days=2)
earthquakes = (Earthquake.objects.
filter(date_time__gt=two_days_ago).
order_by("-date_time").
all())
res = []
for earthquake in earthquakes:
# Формула для вычисления радиуса землетрясения
res.append({
'id': earthquake.id,
'time': earthquake.date_time,
'lat': earthquake.latitude,
'lon': earthquake.longitude,
'depth': earthquake.depth,
'magnitude': earthquake.magnitude,
'region': earthquake.region,
'source': earthquake.source,
})
return JsonResponse(res, safe=False)
except Exception as err:
logging.error(traceback.format_exc())