#!/usr/bin/env python3
"""Verify a single bitable record."""
import json, requests, sys

CRED_FILE = "/root/.openclaw/credentials/xiaoyan/config.json"
APP_TOKEN = "CMHSbUUjka3TrUsaxxEc297ongf"
TABLE_ID = "tblweY65jGBiwSdt"
RECORD_ID = sys.argv[1] if len(sys.argv) > 1 else "recvjhdXiBCoE4"

with open(CRED_FILE) as f:
    cred = json.load(f)
app_id = cred["apps"][0]["appId"]
app_secret = cred["apps"][0]["appSecret"]

token_resp = requests.post(
    "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",
    json={"app_id": app_id, "app_secret": app_secret},
)
token = token_resp.json()["tenant_access_token"]

resp = requests.get(
    f"https://open.feishu.cn/open-apis/bitable/v1/apps/{APP_TOKEN}/tables/{TABLE_ID}/records/{RECORD_ID}",
    headers={"Authorization": f"Bearer {token}"},
)
data = resp.json()
jd = data["data"]["record"]["fields"]["jsonData"]
print(f"jsonData length: {len(jd)} chars")
j = json.loads(jd)
fqs = j["first"]["questionSet"]
sqs = j["second"]["questionSet"]
print(f"first questionSet: {len(fqs)} items")
print(f"second questionSet: {len(sqs)} items")
if fqs:
    for i, q in enumerate(fqs):
        print(f"  first[{i}]: {q['answerText']} | {q['question'][:60]}")
if sqs:
    for i, q in enumerate(sqs):
        print(f"  second[{i}]: {q['answerText']} | {q['question'][:60]}")
