mirror of
https://github.com/NohamR/OqeeAdWatch.git
synced 2026-01-11 16:58:25 +00:00
Add date filtering to ad break inspection
This commit is contained in:
@@ -58,17 +58,27 @@ def _human_ts(ts_value: int) -> str:
|
|||||||
return datetime.fromtimestamp(ts_value).strftime("%Y-%m-%d %H:%M:%S")
|
return datetime.fromtimestamp(ts_value).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
def _load_rows(channel_id: str) -> list[Row]:
|
def _load_rows(
|
||||||
|
channel_id: str, start_date: str | None = None, end_date: str | None = None
|
||||||
|
) -> list[Row]:
|
||||||
conn = get_connection(DB_PATH)
|
conn = get_connection(DB_PATH)
|
||||||
try:
|
try:
|
||||||
cursor = conn.execute(
|
query = """
|
||||||
"""
|
|
||||||
SELECT channel_id, start_ts, end_ts, ad_date
|
SELECT channel_id, start_ts, end_ts, ad_date
|
||||||
FROM ads WHERE channel_id = ?
|
FROM ads WHERE channel_id = ?
|
||||||
ORDER BY start_ts ASC
|
"""
|
||||||
""",
|
params = [channel_id]
|
||||||
(channel_id,),
|
|
||||||
)
|
if start_date:
|
||||||
|
query += " AND ad_date >= ?"
|
||||||
|
params.append(start_date)
|
||||||
|
if end_date:
|
||||||
|
query += " AND ad_date <= ?"
|
||||||
|
params.append(end_date)
|
||||||
|
|
||||||
|
query += " ORDER BY start_ts ASC"
|
||||||
|
|
||||||
|
cursor = conn.execute(query, params)
|
||||||
return cursor.fetchall()
|
return cursor.fetchall()
|
||||||
except sqlite3.OperationalError as exc: # pragma: no cover - CLI helper
|
except sqlite3.OperationalError as exc: # pragma: no cover - CLI helper
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
@@ -290,6 +300,14 @@ def main() -> None:
|
|||||||
description="Inspect ad breaks for a single channel from the local database.",
|
description="Inspect ad breaks for a single channel from the local database.",
|
||||||
)
|
)
|
||||||
parser.add_argument("channel_id", help="Exact channel identifier to inspect")
|
parser.add_argument("channel_id", help="Exact channel identifier to inspect")
|
||||||
|
parser.add_argument(
|
||||||
|
"--start-date",
|
||||||
|
help="Start date for filtering (YYYY-MM-DD format, inclusive)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--end-date",
|
||||||
|
help="End date for filtering (YYYY-MM-DD format, inclusive)",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-plot",
|
"--no-plot",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -297,7 +315,7 @@ def main() -> None:
|
|||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
rows = _load_rows(args.channel_id)
|
rows = _load_rows(args.channel_id, args.start_date, args.end_date)
|
||||||
stats = _compute_stats(rows)
|
stats = _compute_stats(rows)
|
||||||
_print_stats(args.channel_id, stats)
|
_print_stats(args.channel_id, stats)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user