import json
import sys
import os
import jingrow

def execute(context=None, inputs=None, config=None, **kwargs):
    if context is None:
        context = kwargs.get("context", {})
    if inputs is None:
        inputs = kwargs.get("inputs", {})
    if config is None:
        config = kwargs.get("config", {})
 
    #jingrow.log_error(f"inputs={inputs}, config={config}, context={context}")

    pagetype = inputs.get("pagetype") if isinstance(inputs, dict) else None
    name = inputs.get("name") if isinstance(inputs, dict) else None
    if not (pagetype and name):
        pagetype = (config or {}).get("pagetype") if isinstance(config, dict) else None
        name = (config or {}).get("name") if isinstance(config, dict) else None
    if not pagetype or not name:
        return {"success": False, "error": "缺少pagetype或name"}
    try:
        data = jingrow.get_pg(pagetype, name)
        if not data:
            return {"success": False, "error": "获取记录失败"}
        if isinstance(data, dict):
            data["success"] = True
            return data
        return {"success": True, "data": data}
    except Exception as e:
        return {"success": False, "error": str(e)} 