"""Сколько AutoInfo за 19.07.2026."""
from __future__ import annotations

import asyncio
import sys
from datetime import datetime
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))


async def main() -> None:
    from sqlalchemy import func, select

    from app.database.engine import async_session
    from app.database.models import AutoInfo

    start = datetime(2026, 7, 19, 0, 0, 0)
    end = datetime(2026, 7, 19, 23, 59, 59)
    async with async_session() as s:
        today = (
            await s.execute(
                select(func.count())
                .select_from(AutoInfo)
                .where(AutoInfo.created_at >= start, AutoInfo.created_at <= end)
            )
        ).scalar_one()
        total = (await s.execute(select(func.count()).select_from(AutoInfo))).scalar_one()
        rows = list(
            (
                await s.execute(
                    select(AutoInfo)
                    .where(AutoInfo.created_at >= start, AutoInfo.created_at <= end)
                    .order_by(AutoInfo.created_at)
                )
            )
            .scalars()
            .all()
        )
    print(f"today={today} total={total}")
    for x in rows:
        print(x.created_at, x.ad_id, x.name, x.link)


if __name__ == "__main__":
    asyncio.run(main())
