- bot_regional.py: parse BOT BTWS_STAT regional report (reportID per region) -> private consumption index + nondurable index + monthly series - North reportID=954 verified live (idx 100.3, series 6mo); region-keyed for extension to other regions - collect_bot_regional.py CLI -> JSON snapshot - 4 tests; full backend suite 152 OK; compileall ok
32 lines
947 B
Python
32 lines
947 B
Python
"""Collect BOT regional private-consumption index for a region to a JSON snapshot."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from datetime import datetime, timezone
|
|
|
|
from app import bot_regional
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--region", default="north",
|
|
help="BOT region (reportID key), default 'north'")
|
|
parser.add_argument("--timeout", type=float, default=30.0)
|
|
args = parser.parse_args()
|
|
|
|
snap = bot_regional.fetch_region(args.region, timeout=args.timeout)
|
|
payload = {
|
|
"source": "bot",
|
|
"retrieved_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"factor": "consumption_regional",
|
|
"data": snap.to_dict(),
|
|
}
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|