Avoid draft files in product-data generation
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from product_data_portable import (
|
||||
DEFAULT_REQUEST_ID,
|
||||
DEFAULT_TIMESTAMP_STEP_MS,
|
||||
@@ -29,6 +31,19 @@ def main() -> int:
|
||||
timestamp_step_ms=int(payload.get("timestamp_step_ms") or DEFAULT_TIMESTAMP_STEP_MS),
|
||||
default_request_id=str(payload.get("default_request_id") or DEFAULT_REQUEST_ID),
|
||||
)
|
||||
records_output_path = str(payload.get("records_output_path") or "").strip()
|
||||
return_records = bool(payload.get("return_records", not records_output_path))
|
||||
if records_output_path:
|
||||
output_path = resolve_portable_path(records_output_path)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
mode = "a" if bool(payload.get("append", False)) else "w"
|
||||
with output_path.open(mode, encoding="utf-8") as fh:
|
||||
for record in result["records"]:
|
||||
fh.write(json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n")
|
||||
result["records_output_path"] = str(output_path)
|
||||
result["record_count"] = len(result["records"])
|
||||
if not return_records:
|
||||
result.pop("records", None)
|
||||
if confirmed_plan_id:
|
||||
result["confirmed_plan_id"] = confirmed_plan_id
|
||||
emit_success(result)
|
||||
|
||||
Reference in New Issue
Block a user