From d2da2d10d84c6ca7e07e964286333cb7847f39dc Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Mon, 5 Feb 2024 20:33:57 +0530 Subject: [PATCH] use timezone.now() --- daras_ai_v2/bots.py | 13 +++++-------- recipes/VideoBots.py | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/daras_ai_v2/bots.py b/daras_ai_v2/bots.py index edaf0ed32..9f2ebd555 100644 --- a/daras_ai_v2/bots.py +++ b/daras_ai_v2/bots.py @@ -1,16 +1,15 @@ import mimetypes import traceback import typing +from datetime import datetime from urllib.parse import parse_qs -import pytz -from datetime import datetime from django.db import transaction +from django.utils import timezone from fastapi import HTTPException, Request from furl import furl from sentry_sdk import capture_exception -from daras_ai_v2 import settings from app_users.models import AppUser from bots.models import ( Platform, @@ -191,7 +190,7 @@ def _on_msg(bot: BotInterface): speech_run = None input_images = None input_documents = None - recieved_time: datetime = datetime.now(tz=pytz.timezone(settings.TIME_ZONE)) + recieved_time: datetime = timezone.now() if not bot.page_cls: bot.send_msg(text=PAGE_NOT_CONNECTED_ERROR) return @@ -463,8 +462,7 @@ def _save_msgs( if speech_run else None ), - response_time=datetime.now(tz=pytz.timezone(settings.TIME_ZONE)) - - received_time, + response_time=timezone.now() - received_time, ) attachments = [] for f_url in (input_images or []) + (input_documents or []): @@ -481,8 +479,7 @@ def _save_msgs( saved_run=SavedRun.objects.get_or_create( workflow=Workflow.VIDEO_BOTS, **furl(url).query.params )[0], - response_time=datetime.now(tz=pytz.timezone(settings.TIME_ZONE)) - - received_time, + response_time=timezone.now() - received_time, ) # save the messages & attachments with transaction.atomic(): diff --git a/recipes/VideoBots.py b/recipes/VideoBots.py index 5d23502ff..75615e6a7 100644 --- a/recipes/VideoBots.py +++ b/recipes/VideoBots.py @@ -1124,9 +1124,9 @@ def slack_specific_settings(self, bi: BotIntegration): st.session_state[f"_bi_name_{bi.id}"] = ( pr and pr.title ) or self.get_recipe_title() - st.session_state[f"_bi_slack_read_receipt_msg_{bi.id}"] = ( - BotIntegration._meta.get_field("slack_read_receipt_msg").default - ) + st.session_state[ + f"_bi_slack_read_receipt_msg_{bi.id}" + ] = BotIntegration._meta.get_field("slack_read_receipt_msg").default bi.slack_read_receipt_msg = st.text_input( """