Skip to content

Commit

Permalink
fix: adjusted query
Browse files Browse the repository at this point in the history
  • Loading branch information
sakan811 committed Nov 1, 2024
1 parent 20a5f9b commit 82c4998
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions check_missing_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)

Expand Down

0 comments on commit 82c4998

Please sign in to comment.