Files
gti d21a9d1140 Add 'fiscal/' from commit '102ba84500dbd9655a0471288c3e278652593ca9'
git-subtree-dir: fiscal
git-subtree-mainline: d95165fc8f
git-subtree-split: 102ba84500
2026-09-29 14:43:23 -03:00

45 lines
2.0 KiB
Python

"""Verify a small, prioritised sample of CORROBORATED GTINs with OSCBR (free plan). Credentials come ONLY from the Hub environment (OSCBR_TOKEN or OSCBR_USER/OSCBR_PASSWORD).
python -m central.scripts.oscbr_backfill --limit 20 [--dry-run] [--report out.json]
Never spends the operational reserve (PROVIDER_OPERATIONAL_RESERVE_PERCENT), respects 5/min and 50/day, and never queries VERIFIED_KB, CONFLICT or invalid GTINs.
"""
import argparse
import json
import sys
from central.app.config import settings
from central.app.db import SessionLocal
from central.app.enrichment import backfill, history
from central.app.enrichment.providers import build_providers
from central.app.enrichment.quota import ProviderGateway
def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument("--limit", type=int, default=20)
ap.add_argument("--dry-run", action="store_true")
ap.add_argument("--report", default=None)
args = ap.parse_args(argv)
providers = build_providers(settings)
oscbr = next(p for p in providers if p.name == "oscbr")
if not oscbr.provides_ncm and not args.dry_run:
print(json.dumps({"OSCBR_ROLE": "IDENTITY", "reason": "NCM not documented in the V3 contract; backfill for NCM verification is meaningless until proven", "requests": 0}))
return 3
if not oscbr.configured and not args.dry_run:
print(json.dumps({"OSCBR_STATUS": "NOT_CONFIGURED", "requests": 0}))
return 2
with SessionLocal() as session:
current = history.official_sets(session)
report = backfill.run(session, ProviderGateway(session, [oscbr]), oscbr, limit=args.limit, reserve_percent=settings.provider_operational_reserve_percent,
is_official=lambda v: v in current, dry_run=args.dry_run)
text = json.dumps(report, indent=1, default=str)
if args.report:
open(args.report, "w", encoding="utf-8").write(text)
print(text)
return 0
if __name__ == "__main__":
sys.exit(main())