Combines Booking.com Playwright scraper (from forecasting), direct booking engine scraper (ported from laptop-archive/guestline-monitor), and Newbook own-hotel rates into one focused tool. Four views: Bookability, Market View (with price index badges + direct rate sub-rows), Direct Rates (per-competitor room breakdown, min-stay flags, hotel config/discovery), Rate Analysis (advance purchase curve, DOW chart, rate timeline, comparison table). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
963 B
Python
37 lines
963 B
Python
"""
|
|
Database connection and session management
|
|
"""
|
|
import os
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
from sqlalchemy import create_engine
|
|
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://rates:rates_secret@localhost:5432/rates_db")
|
|
|
|
ASYNC_DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://")
|
|
|
|
async_engine = create_async_engine(ASYNC_DATABASE_URL, echo=False)
|
|
AsyncSessionLocal = sessionmaker(
|
|
async_engine, class_=AsyncSession, expire_on_commit=False
|
|
)
|
|
|
|
sync_engine = create_engine(DATABASE_URL)
|
|
SyncSessionLocal = sessionmaker(bind=sync_engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
async def get_db():
|
|
async with AsyncSessionLocal() as session:
|
|
try:
|
|
yield session
|
|
finally:
|
|
await session.close()
|
|
|
|
|
|
def get_sync_db():
|
|
db = SyncSessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|