#!/usr/bin/env python3
"""Orchestration only (2026-10-13): runs collect_trend.py's own list_cell for D on the given months, so three
workers can cover disjoint months in parallel. Same function, same query, same split rule, same files as
`collect_trend.py d`; nothing about the procedure changes. Usage: python3 -I run_d_months.py 2026-04 2026-05"""
import importlib.util, os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
spec = importlib.util.spec_from_file_location("ct", os.path.join(HERE, "collect_trend.py"))
ct = importlib.util.module_from_spec(spec); spec.loader.exec_module(ct)
out = os.path.join(ct.RAW, "d"); os.makedirs(out, exist_ok=True)
log = open(os.path.join(out, "CELLS.log"), "a")
for ym in sys.argv[1:]:
    y, m = map(int, ym.split("-"))
    a, b = ct.month_bounds(y, m)
    ct.list_cell("mcp in:name,description,topics", a, b, out, f"{y}-{m:02d}", log)
    print("d", ym, "done", flush=True)
