From 82c4998034945f5d58337005ea2a524b727486e6 Mon Sep 17 00:00:00 2001 From: Sakan Date: Sat, 2 Nov 2024 04:39:13 +0700 Subject: [PATCH] fix: adjusted query --- check_missing_dates.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/check_missing_dates.py b/check_missing_dates.py index 0ad493a..c708d75 100644 --- a/check_missing_dates.py +++ b/check_missing_dates.py @@ -8,7 +8,7 @@ from typing import Any from dotenv import load_dotenv -from sqlalchemy import create_engine, func, Engine +from sqlalchemy import create_engine, func, Engine, extract, Date, String from sqlalchemy.orm import sessionmaker from japan_avg_hotel_price_finder.booking_details import BookingDetails @@ -164,12 +164,17 @@ def find_missing_dates_in_db(self, year: int) -> list[str]: count_of_date_by_mth_as_of_today = ( session.query( - func.strftime('%Y-%m', HotelPrice.Date).label('month'), + func.concat( + extract('year', func.cast(HotelPrice.Date, Date)).cast(String), + '-', + func.lpad(extract('month', func.cast(HotelPrice.Date, Date)).cast(String), + 2, '0') + ).label('month'), func.count(func.distinct(HotelPrice.Date)).label('count') ) .filter(HotelPrice.City == self.city) - .filter(func.date(HotelPrice.AsOf) == func.date('now')) - .group_by(func.strftime('%Y-%m', HotelPrice.Date)) + .filter(func.cast(HotelPrice.AsOf, Date) == func.current_date()) + .group_by('month') .all() )