Files
ewoooc/scripts/market_intel_seed_writer.py

63 lines
1.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Market intelligence seed writer CLI skeleton.
This script intentionally refuses real writes in the current phase. It prints a
JSON execution plan and never creates a DB session or commits seed rows.
"""
import argparse
import contextlib
import json
import os
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
with contextlib.redirect_stdout(sys.stderr):
from services.market_intel import MarketIntelService # noqa: E402
from services.market_intel.seed_writer_cli import APPROVAL_ENV_VAR # noqa: E402
def parse_args(argv=None):
parser = argparse.ArgumentParser(
description="Preview market_intel platform seed writer execution."
)
parser.add_argument(
"--platform",
default="all",
help="Platform code to preview, or all. Default: all.",
)
parser.add_argument(
"--execute",
action="store_true",
help="Request real execution. This skeleton will still block it.",
)
parser.add_argument(
"--approval-token",
default=None,
help=f"One-time approval token. May also be set via {APPROVAL_ENV_VAR}.",
)
return parser.parse_args(argv)
def main(argv=None):
args = parse_args(argv)
approval_token = args.approval_token or os.getenv(APPROVAL_ENV_VAR)
service = MarketIntelService()
plan = service.build_seed_writer_cli_status(
platform_code=args.platform,
execute_requested=args.execute,
approval_token=approval_token,
)
print(json.dumps(plan, ensure_ascii=False, indent=2, sort_keys=True))
return int(plan.get("exit_code", 2))
if __name__ == "__main__":
raise SystemExit(main())