#!/usr/bin/env python3
"""Generate 7 new writing/speaking records: 022101, 022201, 022301, 022401"""
import requests, json, time

APP_TOKEN = "CMHSbUUjka3TrUsaxxEc297ongf"
APP_ID = "cli_a931175d41799cc7"
APP_SECRET = "Iw2vEfbjT6GtV0GhbxbZqfQ4nAPtbR14"
BASE = "https://open.feishu.cn/open-apis/bitable/v1"

def get_token():
    r = requests.post("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",
        json={"app_id": APP_ID, "app_secret": APP_SECRET}, timeout=10)
    return r.json()["tenant_access_token"]

def create_record(token, table_id, fields):
    r = requests.post(f"{BASE}/apps/{APP_TOKEN}/tables/{table_id}/records",
        headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
        json={"fields": fields}, timeout=15)
    return r.json()

def verify(token, table_id, rid, qsid):
    r = requests.get(f"{BASE}/apps/{APP_TOKEN}/tables/{table_id}/records/{rid}",
        headers={"Authorization": f"Bearer {token}"}, timeout=10)
    f = r.json().get("data",{}).get("record",{}).get("fields",{})
    ds = f.get("dataStatus","?")
    fqsid = f.get("题目集合 ID","?")
    jd = json.loads(f.get("jsonData","{}"))
    tp = jd.get("first",{}).get("type","?")
    oa = len(jd.get("first",{}).get("optionSetList",[]))
    ai = jd.get("first",{}).get("answerSet",[])
    ab = jd.get("first",{}).get("ability",[])
    ex = jd.get("first",{}).get("explanation","")
    qs = len(jd.get("first",{}).get("questionSet",[]))
    sqs = len(jd.get("second",{}).get("questionSet",[]))
    t1 = bool(f.get("题目1",""))
    t2 = bool(f.get("题目2",""))
    pd = bool(f.get("图片描述",""))
    ok = (ds=="0" and fqsid==qsid and t1 and len(ai)>0 and len(ex)>10)
    tag = "✅" if ok else "❌"
    return f"{tag} {qsid} | ds={ds} type={tp} opt={oa} qs={qs}/{sqs} ans={ai} ab={len(ab)} expl={len(ex)} t1={t1} t2={t2} pic={pd}"

# ============================================================
# RECORD DEFINITIONS
# ============================================================

# --- 写作-P1 022101: Urgent help ---
W_022101 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "022101",
        "textDesc": "Your friend Lily left her school bag in the classroom and needs your help to get it back before the weekend. Write an email to help her.<br>Put these sentences in order to make a clear and helpful email.",
        "optionSetList": [
            "Dear Lily,",
            "Is there any chance we can go back to school for your bag now?",
            "If we leave right away, we still have a chance to find it.",
            "We must hurry and call the teacher to avoid being too late.",
            "The only way to get it back is to ask the school guard for help.",
            "How long have you been here waiting for me?",
            "Yours, Sam"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用"],
        "explanation": "按紧急求助邮件的逻辑排列：称呼→询问可能→建议立刻行动→强调紧迫性→给出唯一方案→关心等待→署名。考察is there any chance/we must/the only way等句型和邮件逻辑组织能力。"
    },
    "second": {}
}
W_022101_T1 = """【题目描述】
Your friend Lily left her school bag in the classroom and needs your help to get it back before the weekend. Write an email to help her.
Put these sentences in order to make a clear and helpful email.

【段落列表】
A. Dear Lily,
B. Is there any chance we can go back to school for your bag now?
C. If we leave right away, we still have a chance to find it.
D. We must hurry and call the teacher to avoid being too late.
E. The only way to get it back is to ask the school guard for help.
F. How long have you been here waiting for me?
G. Yours, Sam"""

# --- 写作-P1 022201: Mystery box ---
W_022201 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "022201",
        "textDesc": "Your friend Max found a mysterious old box in the attic. Write an email to share what you found and ask for his help.<br>Put these sentences in order to make a clear email.",
        "optionSetList": [
            "Dear Max,",
            "Why is this old box full of strange papers?",
            "The story behind it is unknown, and even my grandpa avoids talking about it.",
            "This box might be from our great-grandfather's time.",
            "By then, I will have tried to open it with a small key.",
            "That's why I am writing to ask for your help.",
            "Take care, Alex"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用"],
        "explanation": "按分享发现的邮件逻辑排列：称呼→提出问题→描述背景→合理推测→行动预案→请求帮助→署名。考察why is this/the...is unknown/this might be/by then...will have done等句型组织。"
    },
    "second": {}
}
W_022201_T1 = """【题目描述】
Your friend Max found a mysterious old box in the attic. Write an email to share what you found and ask for his help.
Put these sentences in order to make a clear email.

【段落列表】
A. Dear Max,
B. Why is this old box full of strange papers?
C. The story behind it is unknown, and even my grandpa avoids talking about it.
D. This box might be from our great-grandfather's time.
E. By then, I will have tried to open it with a small key.
F. That's why I am writing to ask for your help.
G. Take care, Alex"""

# --- 写作-P1 022301: Community garden ---
W_022301 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "022301",
        "textDesc": "You and your friend Emma are working on a community garden project. Write an email to tell her about today's progress and the plan for next time.<br>Put these sentences in order to make a clear email.",
        "optionSetList": [
            "Dear Emma,",
            "We came here to work together and make our town more beautiful.",
            "So we worked fast before the sun got too hot.",
            "It took us two hours to return to the community garden today.",
            "The photos showed the garden was full of pretty flowers now.",
            "I will plant new seeds while you will water the young trees.",
            "Your friend, Lily"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用"],
        "explanation": "按社区活动汇报的逻辑排列：称呼→说明目的→描述行动→补充细节→展示成果→分配未来任务→署名。考察we came here to/so...worked/the photos showed/while...will等句型和邮件叙事组织能力。"
    },
    "second": {}
}
W_022301_T1 = """【题目描述】
You and your friend Emma are working on a community garden project. Write an email to tell her about today's progress and the plan for next time.
Put these sentences in order to make a clear email.

【段落列表】
A. Dear Emma,
B. We came here to work together and make our town more beautiful.
C. So we worked fast before the sun got too hot.
D. It took us two hours to return to the community garden today.
E. The photos showed the garden was full of pretty flowers now.
F. I will plant new seeds while you will water the young trees.
G. Your friend, Lily"""

# --- 写作-P1 022401: Hospital visit ---
W_022401 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "022401",
        "textDesc": "You and your friend Tom visited Jack in the hospital today. Write an email to Sophie to tell her about the visit and what you plan to do next.<br>Put these sentences in order to make a clear email.",
        "optionSetList": [
            "Dear Sophie,",
            "Tom and I went to the hospital to find our friend Jack today.",
            "The nurse used a machine to check his temperature before we went in.",
            "After saying goodbye, we hurried to tell his mum that he was feeling better.",
            "Then we will bring him his homework and some snacks tomorrow.",
            "You have already done so much by sending him that lovely card.",
            "Warmly, Lily"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用"],
        "explanation": "按医院探病汇报的逻辑排列：称呼→说明探病行动→描述检查过程→告别后通知→后续计划→感谢帮助→署名。考察go to...to find/use...to check/after doing/have already done等句型组织。"
    },
    "second": {}
}
W_022401_T1 = """【题目描述】
You and your friend Tom visited Jack in the hospital today. Write an email to Sophie to tell her about the visit and what you plan to do next.
Put these sentences in order to make a clear email.

【段落列表】
A. Dear Sophie,
B. Tom and I went to the hospital to find our friend Jack today.
C. The nurse used a machine to check his temperature before we went in.
D. After saying goodbye, we hurried to tell his mum that he was feeling better.
E. Then we will bring him his homework and some snacks tomorrow.
F. You have already done so much by sending him that lovely card.
G. Warmly, Lily"""

# ============================================================
# SPEAKING RECORDS
# ============================================================

# --- 口语-P1 022101: Learning experiences ---
S1_022101 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "teacher,gave,seeds,garden,explained,moon,Earth,experiment,proud,found,stone,shell,gift,present,map",
        "questionSetID": "022101",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实经历和想法。",
        "questionSet": [
            {
                "content": "Tell us about a time your teacher gave you something special. What was it?",
                "ability": ["经历描述"],
                "explanation": "用过去式描述老师给过你的特别的东西。用 '...gave us... and...' 的句型，例如 'Our art teacher gave us some paint and paper for a special project last week.'"
            },
            {
                "content": "Who once explained something that you didn't understand? What did they say?",
                "ability": ["经历描述"],
                "explanation": "描述谁给你解释过你不理解的事情。用 '...explained that...' 的句型，例如 'My dad explained that the stars are very, very far away from the Earth.'"
            },
            {
                "content": "What did you do after finishing a difficult task? How did you feel?",
                "ability": ["经历描述"],
                "explanation": "用 'After doing...' 开头描述完成后的感受。例如 'After doing the science experiment, we felt very proud and wanted to show everyone the results.'"
            },
            {
                "content": "What interesting thing have you found in an unexpected place?",
                "ability": ["经历描述"],
                "explanation": "描述你在不寻常的地方发现过什么。用 '... found... in/on...' 的句型，例如 'I found a beautiful seashell on the playground last Friday.'"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "gave,help,learn,explained,game,sport,searching,found,brave,felt,happy,excited,proud,surprised",
        "questionSetID": "022101",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实经历和想法。",
        "questionSet": [
            {
                "content": "What did someone give you that helped you learn something new?",
                "ability": ["经历描述"],
                "explanation": "分享别人给过你什么帮助了你学习新东西。例如 'My grandpa gave me a small map and a compass for our hiking trip. It helped me learn how to find directions.'"
            },
            {
                "content": "Who explained a difficult game or sport to you? What happened?",
                "ability": ["经历描述"],
                "explanation": "描述谁给你解释过一项困难的运动或游戏。例如 'My cousin explained that in chess, each piece moves in a different way. It took a long time for me to remember all the rules.'"
            },
            {
                "content": "What did you find after searching for a long time?",
                "ability": ["经历描述"],
                "explanation": "分享你找了很久才找到的东西。例如 'I found my favourite book under the sofa after searching the whole house for nearly one hour.'"
            },
            {
                "content": "After doing something brave, how did you feel? Tell us about it.",
                "ability": ["经历描述"],
                "explanation": "描述你做过一件勇敢的事后的感受。例如 'After doing my first school speech, I felt so happy and surprised that I could do it. The whole class clapped for me.'"
            }
        ]
    }
}
S1_022101_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实经历和想法。

【热词】
teacher,gave,seeds,garden,explained,moon,Earth,experiment,proud,found,stone,shell

【题目】
1. Tell us about a time your teacher gave you something special. What was it?
- 解析：用过去式描述老师给过你的特别的东西。用 '...gave us... and...' 的句型，例如 'Our art teacher gave us some paint and paper for a special project last week.'

2. Who once explained something that you didn't understand? What did they say?
- 解析：描述谁给你解释过你不理解的事情。用 '...explained that...' 的句型，例如 'My dad explained that the stars are very, very far away from the Earth.'

3. What did you do after finishing a difficult task? How did you feel?
- 解析：用 'After doing...' 开头描述完成后的感受。例如 'After doing the science experiment, we felt very proud and wanted to show everyone the results.'

4. What interesting thing have you found in an unexpected place?
- 解析：描述你在不寻常的地方发现过什么。用 '... found... in/on...' 的句型，例如 'I found a beautiful seashell on the playground last Friday.'"""
S1_022101_T2 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实经历和想法。

【热词】
gave,help,learn,explained,game,sport,searching,found,brave,felt,happy,excited,surprised,proud

【题目】
1. What did someone give you that helped you learn something new?
- 解析：分享别人给过你什么帮助了你学习新东西。例如 'My grandpa gave me a small map and a compass for our hiking trip. It helped me learn how to find directions.'

2. Who explained a difficult game or sport to you? What happened?
- 解析：描述谁给你解释过一项困难的运动或游戏。例如 'My cousin explained that in chess, each piece moves in a different way. It took a long time for me to remember all the rules.'

3. What did you find after searching for a long time?
- 解析：分享你找了很久才找到的东西。例如 'I found my favourite book under the sofa after searching the whole house for nearly one hour.'

4. After doing something brave, how did you feel? Tell us about it.
- 解析：描述你做过一件勇敢的事后的感受。例如 'After doing my first school speech, I felt so happy and surprised that I could do it. The whole class clapped for me.'"""

# --- 口语-P2 022201: Teamwork (WITH IMAGES) ---
S2_022201 = {
    "first": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "plan,list,project,team,disagree,talk,together,poster,colourful,computer,work,help,finish,share,great",
        "questionSetID": "022201",
        "textDesc": "Here are some pictures about working on a school project with classmates. What do you think about these situations?",
        "imageDesc": "Four images show a group of students working on a school project together: 1st: Students sit around a desk with a plan sheet and coloured pencils, discussing their project. 2nd: Two students face each other unhappily, and a teacher bends down to help them work together. 3rd: Students use a laptop and coloured paper to make a poster, with one writing and others drawing. 4th: All students hold up their finished team project, each with a big smile on their faces.",
        "textImage": "022201-00.png",
        "questionSet": [
            {
                "content": "How do you start a group project with your classmates?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "'Let's plan it first and make a to-do list together.' 然后用这个开始描述你们的项目流程，也可以说说谁负责什么。"
            },
            {
                "content": "What happened when your team disagreed about something?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'They argued at first, and then we sat down and talked about it.' 描述一次团队有不同意见的经历，以及你们是怎么解决的。"
            },
            {
                "content": "What do you use to make your project look great?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "'We'll use colourful paper and markers to make our poster stand out.' 说说你们用什么工具和材料让项目作品看起来更好。"
            },
            {
                "content": "What must everyone do to finish the project on time?",
                "ability": ["句型组织", "表达要求"],
                "explanation": "'Everyone must bring their part and help each other.' 解释团队合作中每个人需要做什么才能按时完成。"
            },
            {
                "content": "Tell us about a time your team did a really great job.",
                "ability": ["句型组织", "经历描述"],
                "explanation": "分享一次团队合作成功的经历。例如 'Last month, our team made a poster about saving water. We won the school prize, and I felt so proud of our teamwork.'"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "plan,list,project,team,disagree,talk,together,poster,colourful,computer,work,help,finish,share,great",
        "questionSetID": "022201",
        "textDesc": "Now look at these pictures again. Think about a different project or situation and share more ideas about working with others.",
        "imageDesc": "Same images as above: students working on a school project together.",
        "textImage": "022201-01.png",
        "questionSet": [
            {
                "content": "How do you plan a school party or event with your classmates?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "'Let's plan the games first and make a decoration list together.' 分享你们如何组织一场活动或派对。"
            },
            {
                "content": "What did your friend do at first when things went wrong?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'They felt worried at first, and then we helped each other find a solution.' 说说当事情出错时你们是怎么一起面对的。"
            },
            {
                "content": "What tools or objects will you use to finish a big task?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "'We will use a big calendar to plan our time and make sure we don't forget anything.' 说说你们计划用什么来高效完成任务。"
            },
            {
                "content": "What rules must everyone follow when working as a team?",
                "ability": ["句型组织", "表达要求"],
                "explanation": "'Everyone must listen to each other and share their ideas fairly.' 制定几条团队合作的基本规则。"
            },
            {
                "content": "What was the most fun thing you ever did together as a group?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "分享一个有趣的团队经历。例如 'Last summer, our group cleaned the park near our school. After finishing, we had a small picnic together, and it was the most fun I have ever had with my classmates.'"
            }
        ]
    }
}
S2_022201_T1 = """【题目描述】
Here are some pictures about working on a school project with classmates. What do you think about these situations?

【热词】
plan,list,project,team,disagree,talk,together,poster,colourful,computer,work,help

【图片描述】
Four images show a group of students working on a school project together: 1st: Students sit around a desk with a plan sheet and coloured pencils, discussing their project. 2nd: Two students face each other unhappily, and a teacher bends down to help them work together. 3rd: Students use a laptop and coloured paper to make a poster, with one writing and others drawing. 4th: All students hold up their finished team project, each with a big smile on their faces.

【题目】
1. How do you start a group project with your classmates?
- 解析：'Let's plan it first and make a to-do list together.' 然后用这个开始描述你们的项目流程，也可以说说谁负责什么。

2. What happened when your team disagreed about something?
- 解析：'They argued at first, and then we sat down and talked about it.' 描述一次团队有不同意见的经历，以及你们是怎么解决的。

3. What do you use to make your project look great?
- 解析：'We'll use colourful paper and markers to make our poster stand out.' 说说你们用什么工具和材料让项目作品看起来更好。

4. What must everyone do to finish the project on time?
- 解析：'Everyone must bring their part and help each other.' 解释团队合作中每个人需要做什么才能按时完成。

5. Tell us about a time your team did a really great job.
- 解析：分享一次团队合作成功的经历。例如 'Last month, our team made a poster about saving water. We won the school prize, and I felt so proud of our teamwork.'"""
S2_022201_T2 = """【题目描述】
Now look at these pictures again. Think about a different project or situation and share more ideas about working with others.

【热词】
plan,list,project,team,disagree,talk,together,poster,colourful,computer,work,help

【图片描述】
Same images as above: students working on a school project together.

【题目】
1. How do you plan a school party or event with your classmates?
- 解析：'Let's plan the games first and make a decoration list together.' 分享你们如何组织一场活动或派对。

2. What did your friend do at first when things went wrong?
- 解析：'They felt worried at first, and then we helped each other find a solution.' 说说当事情出错时你们是怎么一起面对的。

3. What tools or objects will you use to finish a big task?
- 解析：'We will use a big calendar to plan our time and make sure we don't forget anything.' 说说你们计划用什么来高效完成任务。

4. What rules must everyone follow when working as a team?
- 解析：'Everyone must listen to each other and share their ideas fairly.' 制定几条团队合作的基本规则。

5. What was the most fun thing you ever did together as a group?
- 解析：分享一个有趣的团队经历。例如 'Last summer, our group cleaned the park near our school. After finishing, we had a small picnic together, and it was the most fun I have ever had with my classmates.'"""
# Image prompts for 口语-P2 022201
S2_022201_PIC = '[1-组图]:{"prompt_2":"黑白线条图:一组学生在教室里围坐在课桌前，桌上放着计划表和彩色铅笔，他们正在热烈讨论项目内容","prompt_3":"黑白线条图:两个学生面对面站着表情不悦，旁边一位老师弯腰用手势示意让他们一起合作","prompt_4":"黑白线条图:学生们使用笔记本电脑和彩纸制作展示海报，有人写字、有人画图，气氛热烈","prompt_5":"黑白线条图:所有学生一起举起完成的团队作品，每个人脸上带着成功的笑容"}'

# --- 口语-P1 022301: Responsibility ---
S1_022301 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "duty,clean,tidy,classroom,follow,rules,safe,dangerous,environment,rubbish,stop,help,important,everyday",
        "questionSetID": "022301",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实想法和做法。",
        "questionSet": [
            {
                "content": "Why should we take care of our school or neighbourhood?",
                "ability": ["表达观点"],
                "explanation": "'It is our duty to keep our classroom clean and tidy.' 从这个角度说明为什么我们有责任维护身边的环境，可以举一个具体的例子。"
            },
            {
                "content": "What will happen if we don't follow the safety rules?",
                "ability": ["表达观点"],
                "explanation": "'We must follow the safety rules, or our school will be dangerous for everyone.' 说明不遵守规则的后果。"
            },
            {
                "content": "What do we need to make people stop doing to protect the environment?",
                "ability": ["表达建议"],
                "explanation": "'We need to make people stop throwing rubbish on the ground.' 说出你认为需要改变的一种行为，并说明为什么。"
            },
            {
                "content": "What is one of the most important things we should do every day?",
                "ability": ["表达观点"],
                "explanation": "'Helping others is one of the most important things we can do each day.' 用 '...is one of the...' 说出你认为每天最重要的事情之一。"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "duty,home,help,parents,kind,classmates,rules,online,polite,best,ways,support,care,respect",
        "questionSetID": "022301",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实想法。",
        "questionSet": [
            {
                "content": "What else is it our duty to do at home?",
                "ability": ["表达观点"],
                "explanation": "说说你在家里有哪些责任。例如 'It is my duty to help my parents set the table for dinner every evening.'"
            },
            {
                "content": "Why must we be kind to our classmates?",
                "ability": ["表达观点"],
                "explanation": "'We must be kind to our classmates, or our classroom will feel cold and unfriendly.' 说说友善对人的重要性。"
            },
            {
                "content": "What do we need to make people stop doing online?",
                "ability": ["表达建议"],
                "explanation": "'We need to make people stop saying unkind words online.' 说说网络上需要停止的不良行为。"
            },
            {
                "content": "What is one of the best ways to help your parents?",
                "ability": ["表达观点"],
                "explanation": "'Doing my homework without being asked is one of the best ways to help my parents.' 用 '...is one of the...' 分享帮助父母的好方法。"
            }
        ]
    }
}
S1_022301_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实想法和做法。

【热词】
duty,clean,tidy,classroom,follow,rules,safe,dangerous,environment,rubbish,stop,important,everyday

【题目】
1. Why should we take care of our school or neighbourhood?
- 解析：'It is our duty to keep our classroom clean and tidy.' 从这个角度说明为什么我们有责任维护身边的环境，可以举一个具体的例子。

2. What will happen if we don't follow the safety rules?
- 解析：'We must follow the safety rules, or our school will be dangerous for everyone.' 说明不遵守规则的后果。

3. What do we need to make people stop doing to protect the environment?
- 解析：'We need to make people stop throwing rubbish on the ground.' 说出你认为需要改变的一种行为，并说明为什么。

4. What is one of the most important things we should do every day?
- 解析：'Helping others is one of the most important things we can do each day.' 用 '...is one of the...' 说出你认为每天最重要的事情之一。"""
S1_022301_T2 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实想法。

【热词】
duty,home,help,parents,kind,classmates,rules,online,polite,best,ways,support,care,respect

【题目】
1. What else is it our duty to do at home?
- 解析：说说你在家里有哪些责任。例如 'It is my duty to help my parents set the table for dinner every evening.'

2. Why must we be kind to our classmates?
- 解析：'We must be kind to our classmates, or our classroom will feel cold and unfriendly.' 说说友善对人的重要性。

3. What do we need to make people stop doing online?
- 解析：'We need to make people stop saying unkind words online.' 说说网络上需要停止的不良行为。

4. What is one of the best ways to help your parents?
- 解析：'Doing my homework without being asked is one of the best ways to help my parents.' 用 '...is one of the...' 分享帮助父母的好方法。"""

# --- 口语-P1 022401: Expressing yourself ---
S1_022401 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "want,only,draw,garden,park,understand,homework,first,start,plan,until,finish,turn,TV,game",
        "questionSetID": "022401",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实想法和做法。",
        "questionSet": [
            {
                "content": "If you could choose one thing to do today, what would you want to do?",
                "ability": ["表达喜好"],
                "explanation": "'I only want to spend the afternoon drawing in the garden.' 说出你今天最想做的事，用 'I only want to...' 的句型。"
            },
            {
                "content": "Your friend wants to play but you have homework. What do you say?",
                "ability": ["协商表达"],
                "explanation": "'I understand you want to play, but we must finish our homework first.' 用 'I understand... but...' 来温和地说不。"
            },
            {
                "content": "How do you think we should start a big task?",
                "ability": ["表达建议"],
                "explanation": "'We should start by making a plan and getting all the things we need.' 用 'We should start by...' 说出你的建议。"
            },
            {
                "content": "What won't you do until you finish your work?",
                "ability": ["表达坚持"],
                "explanation": "'I won't turn on the TV until I have done all my homework.' 用 'I won't... until...' 说明你的坚持。"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "weekend,only,relax,read,disagree,friend,listen,talk,start,new,skill,practise,until,ready,perform",
        "questionSetID": "022401",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实想法。",
        "questionSet": [
            {
                "content": "What is something you only want to do on the weekend?",
                "ability": ["表达喜好"],
                "explanation": "'On the weekend, I only want to relax and read my favourite books all morning.' 说说你只在周末想做的事。"
            },
            {
                "content": "When you disagree with a friend, how do you solve it?",
                "ability": ["协商表达"],
                "explanation": "'I understand you are angry, but we must listen to each other and talk about it.' 分享你处理分歧的方式。"
            },
            {
                "content": "How should we start when learning a new skill?",
                "ability": ["表达建议"],
                "explanation": "'We should start by watching someone else do it and then try it ourselves.' 用 'We should start by...' 分享学习方法。"
            },
            {
                "content": "What won't you do until you have practised enough?",
                "ability": ["表达坚持"],
                "explanation": "'I won't perform on the stage until I have practised my piece at least ten times.' 说说你需要充分练习才会去做的事。"
            }
        ]
    }
}
S1_022401_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享你的真实想法和做法。

【热词】
want,only,draw,garden,park,understand,homework,first,start,plan,until,finish,TV,game

【题目】
1. If you could choose one thing to do today, what would you want to do?
- 解析：'I only want to spend the afternoon drawing in the garden.' 说出你今天最想做的事，用 'I only want to...' 的句型。

2. Your friend wants to play but you have homework. What do you say?
- 解析：'I understand you want to play, but we must finish our homework first.' 用 'I understand... but...' 来温和地说不。

3. How do you think we should start a big task?
- 解析：'We should start by making a plan and getting all the things we need.' 用 'We should start by...' 说出你的建议。

4. What won't you do until you finish your work?
- 解析：'I won't turn on the TV until I have done all my homework.' 用 'I won't... until...' 说明你的坚持。"""
S1_022401_T2 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，分享更多你的真实想法。

【热词】
weekend,only,relax,read,disagree,friend,listen,talk,start,new,skill,practise,until,ready,perform

【题目】
1. What is something you only want to do on the weekend?
- 解析：'On the weekend, I only want to relax and read my favourite books all morning.' 说说你只在周末想做的事。

2. When you disagree with a friend, how do you solve it?
- 解析：'I understand you are angry, but we must listen to each other and talk about it.' 分享你处理分歧的方式。

3. How should we start when learning a new skill?
- 解析：'We should start by watching someone else do it and then try it ourselves.' 用 'We should start by...' 分享学习方法。

4. What won't you do until you have practised enough?
- 解析：'I won't perform on the stage until I have practised my piece at least ten times.' 说说你需要充分练习才会去做的事。"""

# ============================================================
# MAIN: Create all 7 records
# ============================================================
def main():
    token = get_token()
    print("Token OK\n")

    records = [
        # (label, table, QSID, jsonData, 题目1, 题目2, 图片描述, 题目1热词, 题目2热词)
        ("写作 022101", "tblszuk1TeToofBF", "022101", W_022101, W_022101_T1, "", "", "", ""),
        ("写作 022201", "tblszuk1TeToofBF", "022201", W_022201, W_022201_T1, "", "", "", ""),
        ("写作 022301", "tblszuk1TeToofBF", "022301", W_022301, W_022301_T1, "", "", "", ""),
        ("写作 022401", "tblszuk1TeToofBF", "022401", W_022401, W_022401_T1, "", "", "", ""),
        ("口语-P1 022101", "tblRGv7k4WH58Jgq", "022101", S1_022101, S1_022101_T1, S1_022101_T2, "",
         "teacher,gave,seeds,garden,explained,moon,Earth,experiment,found",
         "gave,help,learn,explained,game,searching,found,brave,happy"),
        ("口语-P2 022201", "tblGoWYBmVI0IrvQ", "022201", S2_022201, S2_022201_T1, S2_022201_T2,
         S2_022201_PIC, "", ""),
        ("口语-P1 022301", "tblRGv7k4WH58Jgq", "022301", S1_022301, S1_022301_T1, S1_022301_T2, "",
         "duty,clean,tidy,classroom,follow,safe,rules,environment,rubbish,important",
         "duty,home,help,parents,kind,classmates,online,best,ways,support"),
        ("口语-P1 022401", "tblRGv7k4WH58Jgq", "022401", S1_022401, S1_022401_T1, S1_022401_T2, "",
         "want,only,draw,garden,understand,homework,start,plan,until,finish,TV",
         "weekend,only,relax,disagree,friend,listen,start,new,skill,practise,until"),
    ]

    results = []
    for label, tid, qsid, jd, t1, t2, pic, kw1, kw2 in records:
        fields = {
            "题目集合 ID": qsid,
            "dataStatus": "0",
            "jsonData": json.dumps(jd, ensure_ascii=False),
            "题目1": t1,
        }
        if t2:
            fields["题目2"] = t2
        if pic:
            fields["图片描述"] = pic
        if kw1:
            fields["题目1热词"] = kw1
        if kw2:
            fields["题目2热词"] = kw2

        resp = create_record(token, tid, fields)
        code = resp.get("code")
        if code == 0:
            rid = resp["data"]["record"]["record_id"]
            # Verify
            time.sleep(0.5)
            v = verify(token, tid, rid, qsid)
            print(f"[{'✅' if '✅' in v else '❌'}] {label} → {rid}")
            print(f"    {v}")
            results.append((label, qsid, rid, "✅" in v))
        else:
            print(f"[❌] {label} FAILED: code={code} msg={resp.get('msg')}")
            results.append((label, qsid, "FAIL", False))

    # Summary
    ok = sum(1 for r in results if r[3])
    print(f"\n=== 完成: {ok}/{len(results)} 条创建成功 ===")

if __name__ == "__main__":
    main()
