diff --git a/anyway/infographic_image_generator.py b/anyway/infographic_image_generator.py index 36f4e72d..6878a871 100644 --- a/anyway/infographic_image_generator.py +++ b/anyway/infographic_image_generator.py @@ -29,6 +29,7 @@ def create_chrome_browser_session(newsflash_id): "profile.content_settings.exceptions.automatic_downloads.*.setting": 1, } options.add_experimental_option("prefs", prefs) + options.add_argument("--incognito") browser = webdriver.Remote( command_executor=selenium_hub_url, diff --git a/anyway/infographics_utils.py b/anyway/infographics_utils.py index 6eb57f53..b48514eb 100755 --- a/anyway/infographics_utils.py +++ b/anyway/infographics_utils.py @@ -265,3 +265,8 @@ def get_infographics_mock_data(): mock_data[WIDGETS].append(widget) mock_data[WIDGETS] = sorted(mock_data[WIDGETS], key=lambda widget: widget[META]["rank"]) return mock_data + + +def get_infographics_data_by_newsflash(newsflash_id): + request_params = get_request_params_from_request_values({"news_flash_id": newsflash_id}) + return get_infographics_data_for_location(request_params) \ No newline at end of file diff --git a/anyway/telegram_accident_notifications.py b/anyway/telegram_accident_notifications.py index 7376c731..aac2d24a 100644 --- a/anyway/telegram_accident_notifications.py +++ b/anyway/telegram_accident_notifications.py @@ -4,6 +4,7 @@ from anyway.models import TelegramForwardedMessages from anyway.utilities import trigger_airflow_dag from anyway.app_and_db import db +from anyway.infographics_utils import get_infographics_data_by_newsflash import telebot import boto3 import time @@ -77,33 +78,9 @@ def publish_notification(newsflash_id, chat_id=TELEGRAM_CHANNEL_CHAT_ID): db.session.commit() -def fetch_widgets_with_retries(newsflash_id, wait_times): - url = f"https://www.anyway.co.il/api/infographics-data?news_flash_id={newsflash_id}" - for attempt, wait_time in enumerate(wait_times): - try: - logging.debug(f"Attempt {attempt + 1}: Fetching data widgets for newsflash {newsflash_id}") - response = requests.get(url) - if response.ok: - response_json = response.json() - widgets = response_json.get("widgets", []) - if len(widgets) > 0: - return widgets - except requests.exceptions.RequestException as e: - logging.debug(e) - time.sleep(wait_time) - raise RuntimeError(f"Failed to fetch data from {url}") - - -def fetch_widgets(newsflash_id): - retry_timeouts = [10, 20, 30, 60] - widgets = fetch_widgets_with_retries(newsflash_id, retry_timeouts) - return [widget.get("name") for widget in widgets] - - def get_items_for_send(newsflash_id): items = [] - retry_timeouts = [10, 20, 30, 60] - widgets = fetch_widgets_with_retries(newsflash_id, retry_timeouts) + widgets = get_infographics_data_by_newsflash(newsflash_id)["widgets"] transcription_by_widget_name = get_transcription_by_widget_name(widgets) urls_by_infographic_name = create_public_urls_for_infographics_images(str(newsflash_id)) for widget in widgets: @@ -157,4 +134,4 @@ def trigger_generate_infographics_and_send_to_telegram(newsflash_id, pre_verific dag_conf = {"news_flash_id": newsflash_id} dag_conf["chat_id"] = TELEGRAM_CHANNEL_CHAT_ID if pre_verification_chat \ else TELEGRAM_POST_VERIFICATION_CHANNEL_CHAT_ID - trigger_airflow_dag("generate-and-send-infographics-images", dag_conf) \ No newline at end of file + trigger_airflow_dag("generate-and-send-infographics-images", dag_conf) diff --git a/anyway/views/news_flash/api.py b/anyway/views/news_flash/api.py index 67bdb45b..a67781d3 100644 --- a/anyway/views/news_flash/api.py +++ b/anyway/views/news_flash/api.py @@ -375,8 +375,10 @@ def update_news_flash_qualifying(id): new_location=new_location, new_qualification=new_location_qualifiction, ) + VERIFIED_QUALIFICATIONS = [NewsflashLocationQualification.MANUAL.value, + NewsflashLocationQualification.VERIFIED.value] if os.environ.get("FLASK_ENV") == "production" and \ - new_location_qualifiction == NewsflashLocationQualification.MANUAL.value and \ + new_location_qualifiction in VERIFIED_QUALIFICATIONS and \ old_location_qualifiction != NewsflashLocationQualification.MANUAL.value: trigger_generate_infographics_and_send_to_telegram(id, False) return Response(status=HTTPStatus.OK)