From c4195cf94f0f2e94721f8e0d1089cdadddb8caf5 Mon Sep 17 00:00:00 2001 From: tkalir Date: Tue, 23 Apr 2024 19:06:23 +0300 Subject: [PATCH] fixing dag triggering --- anyway/telegram_accident_notifications.py | 2 +- anyway/views/news_flash/api.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/anyway/telegram_accident_notifications.py b/anyway/telegram_accident_notifications.py index 92595758..abecd469 100644 --- a/anyway/telegram_accident_notifications.py +++ b/anyway/telegram_accident_notifications.py @@ -116,7 +116,7 @@ def create_public_urls_for_infographics_images(folder_name): presigned_urls[infographic_name] = url return presigned_urls -@staticmethod + def trigger_generate_infographics_and_send_to_telegram(newsflash_id, pre_verification_chat=True): dag_conf = {"news_flash_id": newsflash_id} dag_conf["chat_id"] = TELEGRAM_CHANNEL_CHAT_ID if pre_verification_chat \ diff --git a/anyway/views/news_flash/api.py b/anyway/views/news_flash/api.py index 4cf8a8ce..d1bf7f06 100644 --- a/anyway/views/news_flash/api.py +++ b/anyway/views/news_flash/api.py @@ -5,6 +5,7 @@ import json import logging import pandas as pd +import os from typing import List, Optional from http import HTTPStatus @@ -13,7 +14,6 @@ from flask import request, Response, make_response, jsonify from sqlalchemy import and_, not_, or_ - from anyway.app_and_db import db from anyway.backend_constants import ( BE_CONST, @@ -38,8 +38,8 @@ DEFAULT_LIMIT_REQ_PARAMETER = 100 DEFAULT_NUMBER_OF_YEARS_AGO = 5 -class NewsFlashQuery(BaseModel): +class NewsFlashQuery(BaseModel): id: Optional[int] road_number: Optional[int] offset: Optional[int] = DEFAULT_OFFSET_REQ_PARAMETER @@ -407,7 +407,8 @@ def update_news_flash_qualifying(id): new_location=new_location, new_qualification=new_location_qualifiction, ) - if new_location_qualifiction == NewsflashLocationQualification.MANUAL.value and \ + if os.environ.get("FLASK_ENV") == "production" and \ + new_location_qualifiction == NewsflashLocationQualification.MANUAL.value and \ old_location_qualifiction != NewsflashLocationQualification.MANUAL.value: trigger_generate_infographics_and_send_to_telegram(id, False) return Response(status=HTTPStatus.OK) @@ -469,7 +470,6 @@ def get_downloaded_data(format, years_ago): columns[AccidentMarkerView.x] = 'X קואורדינטה' columns[AccidentMarkerView.y] = 'Y קואורדינטה' - related_accidents = get_accidents_stats( table_obj=AccidentMarkerView, columns=columns.keys(),