#!/usr/bin/env python3
"""Generate 10 new writing/speaking C-level records: 032501-032901"""
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(token, tid, fields):
    r = requests.post(f"{BASE}/apps/{APP_TOKEN}/tables/{tid}/records",
        headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
        json={"fields": fields}, timeout=15)
    return r.json()

# ============================================================
# WRITING 032501 - Expressing doubt + encouragement
# ============================================================
W_032501 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "032501",
        "textDesc": "Your friend Ben is worried about the school concert and wants to give up. Write an email to encourage him and share your own feelings.<br>Put these sentences in order to make a kind and encouraging email.",
        "optionSetList": [
            "Dear Ben,",
            "I don't believe you should give up so quickly.",
            "I feel a bit nervous about the school concert too.",
            "It sounds like you have practised a lot already.",
            "I am not very good at playing the piano either, but I still try every day.",
            "Yours truly, Sam"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用", "情感表达｜鼓励与共情"],
        "explanation": "按鼓励邮件的逻辑：称呼→表达不认同→分享同感建立共情→肯定对方努力→自谦示范坚持→署名。考察I don't believe/I feel a bit/It sounds like/I am not very good at等句型的组织，以及鼓励信的情感递进逻辑。C级难度体现在需理解共情-肯定-示范三层递进。"
    },
    "second": {}
}
W_032501_T1 = """【题目描述】
Your friend Ben is worried about the school concert and wants to give up. Write an email to encourage him and share your own feelings.
Put these sentences in order to make a kind and encouraging email.

【段落列表】
A. Dear Ben,
B. I don't believe you should give up so quickly.
C. I feel a bit nervous about the school concert too.
D. It sounds like you have practised a lot already.
E. I am not very good at playing the piano either, but I still try every day.
F. Yours truly, Sam"""

# ============================================================
# SPEAKING-P1 032501 - Changes & perspectives
# ============================================================
S1_032501 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "however,sooner,later,depending,used to,change,mind,weather,plan,hobby,habit,past",
        "questionSetID": "032501",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 However、sooner or later、Depending on、used to 等连接结构。",
        "questionSet": [
            {
                "content": "Tell us about a time you changed your mind about something important. What made you change?",
                "ability": ["表达转变", "经历描述"],
                "explanation": "用 'I used to think that... However, I changed my mind when...' 的结构来描述。例如 'I used to think maths was boring. However, after our class built a model bridge, I changed my mind because I saw how useful maths can be.'"
            },
            {
                "content": "What is something that you believe will happen sooner or later? Why do you think so?",
                "ability": ["表达预测", "表达观点"],
                "explanation": "用 'I believe that... sooner or later.' 开头表达你的预测，并解释原因。例如 'I believe people will stop using plastic bags sooner or later, because we are all learning how much it hurts the ocean animals.'"
            },
            {
                "content": "How do your weekend plans change depending on the weather?",
                "ability": ["条件表达", "经历描述"],
                "explanation": "用 'Depending on...' 来描述天气如何影响你的计划。例如 'Depending on the weather, I either go cycling in the park or stay home and read a book. If it rains, I sometimes bake cookies with my mum.'"
            },
            {
                "content": "What is something you or your friends used to do but no longer do? Why did you stop?",
                "ability": ["过去对比", "经历描述"],
                "explanation": "用 'They used to...' 描述过去的习惯，并解释为什么改变了。例如 'We used to play in the sandpit every day after school, but we are too old for it now. Instead, we play football on the field.'"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "however,sooner,later,depending,used to,opinion,technology,environment,future,childhood,memory",
        "questionSetID": "032501",
        "textDesc": "请回答以下问题。继续尝试使用 However、sooner or later、Depending on、used to 等表达方式。",
        "questionSet": [
            {
                "content": "What opinion did you once hold that later turned out to be wrong?",
                "ability": ["表达转变", "经历描述"],
                "explanation": "用 'I used to believe that... However,...' 分享一次错误的看法及如何被纠正的经历。"
            },
            {
                "content": "What technology do you think will change our lives sooner or later?",
                "ability": ["表达预测", "表达观点"],
                "explanation": "用 'I think that... sooner or later.' 来预测某项技术的影响。例如人工智能、太空旅行或环保科技。"
            },
            {
                "content": "How do your food choices change depending on the season?",
                "ability": ["条件表达", "经历描述"],
                "explanation": "描述你的饮食如何随季节变化。例如 'Depending on the season, I enjoy different fruits. In summer I love watermelons, but in winter I prefer hot soup.'"
            },
            {
                "content": "What did your parents tell you they used to do when they were your age?",
                "ability": ["过去对比", "经历描述"],
                "explanation": "分享你父母小时候的故事。例如 'My dad said he used to walk two kilometres to school every morning, but I only need five minutes.'"
            }
        ]
    }
}
S1_032501_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 However、sooner or later、Depending on、used to 等连接结构。

【热词】
however,sooner,later,depending,used,change,mind,weather,plan,hobby,habit

【题目】
1. Tell us about a time you changed your mind about something important. What made you change?
- 解析：用 'I used to think that... However, I changed my mind when...' 的结构来描述。

2. What is something that you believe will happen sooner or later? Why do you think so?
- 解析：用 'I believe that... sooner or later.' 开头表达你的预测，并解释原因。

3. How do your weekend plans change depending on the weather?
- 解析：用 'Depending on...' 来描述天气如何影响你的计划。

4. What is something you or your friends used to do but no longer do? Why did you stop?
- 解析：用 'They used to...' 描述过去的习惯，并解释为什么改变了。"""
S1_032501_T2 = """【题目描述】
请回答以下问题。继续尝试使用 However、sooner or later、Depending on、used to 等表达方式。

【热词】
however,sooner,later,depending,used,opinion,technology,future,childhood,memory

【题目】
1. What opinion did you once hold that later turned out to be wrong?
- 解析：用 'I used to believe that... However,...' 分享一次错误的看法及如何被纠正的经历。

2. What technology do you think will change our lives sooner or later?
- 解析：用 'I think that... sooner or later.' 来预测某项技术的影响。

3. How do your food choices change depending on the season?
- 解析：描述你的饮食如何随季节变化。

4. What did your parents tell you they used to do when they were your age?
- 解析：分享你父母小时候的故事。"""

# ============================================================
# WRITING 032601 - Expressing emotions & requests
# ============================================================
W_032601 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "032601",
        "textDesc": "You just came back from a wonderful school trip to the science museum. Write a thank-you email to your teacher, Mr. Brown.<br>Put these sentences in order to make a polite and expressive email.",
        "optionSetList": [
            "Dear Mr. Brown,",
            "I'd like to thank you for the wonderful trip to the science museum.",
            "What a fantastic experience it was!",
            "The planet show was so amazing that I couldn't stop talking about it.",
            "Excuse me, could you please send us the photos you took?",
            "Warm regards, Lucy"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用", "情感表达｜感谢与赞美"],
        "explanation": "按感谢信的逻辑：称呼→表达感谢→感叹赞美→具体描述→礼貌请求→署名。考察I'd like to/What a...!/so...that.../Excuse me,...?等感叹与礼貌请求句型。C级难度体现在感叹句和程度状语从句的运用。"
    },
    "second": {}
}
W_032601_T1 = """【题目描述】
You just came back from a wonderful school trip to the science museum. Write a thank-you email to your teacher, Mr. Brown.
Put these sentences in order to make a polite and expressive email.

【段落列表】
A. Dear Mr. Brown,
B. I'd like to thank you for the wonderful trip to the science museum.
C. What a fantastic experience it was!
D. The planet show was so amazing that I couldn't stop talking about it.
E. Excuse me, could you please send us the photos you took?
F. Warm regards, Lucy"""

# ============================================================
# SPEAKING-P2 032601 - Future dreams
# ============================================================
S2_032601 = {
    "first": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "someday,dream,future,career,goal,choice,astronaut,teacher,doctor,artist,important,family,friends,study",
        "questionSetID": "032601",
        "textDesc": "Here are some pictures about dreams and future plans. What do you think about these situations?",
        "imageDesc": "Four images show children thinking about and planning for the future: 1st: A child stands by the window looking at the starry night sky, with a dreamy expression. 2nd: A child looks at scattered art supplies and books on a desk with a confused expression. 3rd: Children hold up posters of their future career dreams in the classroom. 4th: A teacher writes the word 'Dream' on the blackboard while students raise their hands eagerly.",
        "textImage": "032601-00.png",
        "questionSet": [
            {
                "content": "What profession do you dream of doing someday? Why?",
                "ability": ["句型组织", "表达愿望"],
                "explanation": "'I will become a doctor someday because I want to help sick people get better.' 或者用 'I don't know what to choose yet, but I would like to do something creative.' 来表达你目前的梦想或困惑。"
            },
            {
                "content": "Have you ever not known what to choose or decide? Tell us about it.",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'I don't know what to do when it's time to choose between art class and music class. Both sound fun!' 描述一次你在选择上犹豫的经历。"
            },
            {
                "content": "What kind of life would you like to have when you grow up?",
                "ability": ["句型组织", "表达愿望"],
                "explanation": "'I would like to live near the sea and have a small garden where I can grow flowers.' 描绘你理想中长大后的生活图景。"
            },
            {
                "content": "What do you think is important to achieve your dreams?",
                "ability": ["句型组织", "表达观点"],
                "explanation": "'Hard work is important to achieve any dream. You also need to believe in yourself and never give up, even when things get difficult.' 分享你认为实现梦想所需的重要品质。"
            },
            {
                "content": "Has anyone ever told you something that changed how you think about your future?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "分享一个影响你未来想法的人或话。例如 'My grandpa once told me that it doesn't matter what job you do, as long as you do it with all your heart.'"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "someday,dream,future,career,goal,choice,study,hard,work,believe,important,happy,help",
        "questionSetID": "032601",
        "textDesc": "Now look at these pictures again. Think more deeply about what your dreams mean to you and the people around you.",
        "imageDesc": "Same images as above: children thinking about and planning for the future.",
        "textImage": "032601-01.png",
        "questionSet": [
            {
                "content": "What will you do someday to make your parents proud?",
                "ability": ["句型组织", "表达愿望"],
                "explanation": "'I will study hard someday and go to a good university. I know that would make my parents very proud.' 分享你打算如何让家人骄傲。"
            },
            {
                "content": "What do you still not know about your future that makes you curious?",
                "ability": ["句型组织", "表达困惑"],
                "explanation": "'I don't know what country I will live in or what kind of friends I will have, and that makes me very curious about the future.' 分享你对未来的不确定性。"
            },
            {
                "content": "What skill would you like to learn before you become an adult?",
                "ability": ["句型组织", "表达愿望"],
                "explanation": "'I would like to learn how to play the guitar and how to speak another language before I turn eighteen.' 说说你想在成年之前掌握的技能。"
            },
            {
                "content": "Why is it important to have both big dreams and small goals?",
                "ability": ["句型组织", "表达观点"],
                "explanation": "'Big dreams give us direction, but small goals help us move step by step. Having a big dream is important to stay excited, while small goals show us that we are making progress.'"
            },
            {
                "content": "What advice would you give to a friend who has lost hope in their dream?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "给朋友一些鼓励。例如 'I would tell my friend not to give up. Every successful person failed many times. If you keep trying and learning, your dream will come true someday.'"
            }
        ]
    }
}
S2_032601_T1 = """【题目描述】
Here are some pictures about dreams and future plans. What do you think about these situations?

【热词】
someday,dream,future,career,goal,choice,astronaut,teacher,doctor,artist,important

【图片描述】
Four images show children thinking about and planning for the future: 1st: A child stands by the window looking at the starry night sky, with a dreamy expression. 2nd: A child looks at scattered art supplies and books on a desk with a confused expression. 3rd: Children hold up posters of their future career dreams in the classroom. 4th: A teacher writes the word 'Dream' on the blackboard while students raise their hands eagerly.

【题目】
1. What profession do you dream of doing someday? Why?
- 解析：'I will become a doctor someday because I want to help sick people get better.' 用 'I will... someday.' 表达你的职业梦想。

2. Have you ever not known what to choose or decide? Tell us about it.
- 解析：'I don't know what to do when it's time to choose between art class and music class.' 描述一次选择困难的经历。

3. What kind of life would you like to have when you grow up?
- 解析：'I would like to live near the sea and have a small garden where I can grow flowers.' 描绘理想生活。

4. What do you think is important to achieve your dreams?
- 解析：'Hard work is important to achieve any dream. You also need to believe in yourself.' 分享实现梦想所需品质。

5. Has anyone ever told you something that changed how you think about your future?
- 解析：分享一个影响你未来想法的人或话。"""
S2_032601_T2 = """【题目描述】
Now look at these pictures again. Think more deeply about what your dreams mean to you and the people around you.

【热词】
someday,dream,future,career,goal,choice,study,hard,work,believe,important,happy

【图片描述】
Same images as above: children thinking about and planning for the future.

【题目】
1. What will you do someday to make your parents proud?
- 解析：'I will study hard someday and go to a good university.' 分享你打算如何让家人骄傲。

2. What do you still not know about your future that makes you curious?
- 解析：'I don't know what country I will live in or what kind of friends I will have.' 分享对未来的好奇。

3. What skill would you like to learn before you become an adult?
- 解析：'I would like to learn how to play the guitar and how to speak another language.' 说说你想学会的技能。

4. Why is it important to have both big dreams and small goals?
- 解析：解释远大梦想和短期目标各自的重要性。

5. What advice would you give to a friend who has lost hope in their dream?
- 解析：给朋友一些鼓励坚持下去的建议。"""
S2_032601_PIC = '[1-组图]:{"prompt_2":"黑白线条图:一个孩子站在窗边仰望星空，脸上带着憧憬的神情，窗外可见月亮和几颗星星","prompt_3":"黑白线条图:一个孩子坐在桌前，桌上散落着画纸和书本，表情困惑而迷茫","prompt_4":"黑白线条图:教室内孩子们举着自己画的未来职业海报，有宇航员、医生、老师等","prompt_5":"黑白线条图:一位老师在黑板上写着梦想两个字，学生们纷纷举手想要分享"}'

# ============================================================
# WRITING 032701 - Describing people & places
# ============================================================
W_032701 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "032701",
        "textDesc": "You visited a wonderful little café that your cousin found. Write an email to your friend Anna to describe the place, the people you met, and your experience.<br>Put these sentences in order to make a descriptive email.",
        "optionSetList": [
            "Dear Anna,",
            "They are friendly, kind and always ready to help every customer.",
            "She looks different from the photo she sent me last year.",
            "This is a place that makes everyone feel at home.",
            "It is not me who found this wonderful café — my cousin did.",
            "Someone named Lily showed us around the old library nearby.",
            "The hill near the café is too steep to climb without proper shoes.",
            "Kind regards, Emma"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6, 7],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用", "描述性写作｜人物与地点"],
        "explanation": "按描述邮件的逻辑：称呼→描述人物→外貌对比→地点氛围→澄清发现者→补充人名→补充地点→署名。考察They are/looks different from/a place that/it is not...who/someone named/too...to...等多种句型。C级体现在多句型切换和描述性词汇的运用。"
    },
    "second": {}
}
W_032701_T1 = """【题目描述】
You visited a wonderful little café that your cousin found. Write an email to your friend Anna to describe the place, the people you met, and your experience.
Put these sentences in order to make a descriptive email.

【段落列表】
A. Dear Anna,
B. They are friendly, kind and always ready to help every customer.
C. She looks different from the photo she sent me last year.
D. This is a place that makes everyone feel at home.
E. It is not me who found this wonderful café — my cousin did.
F. Someone named Lily showed us around the old library nearby.
G. The hill near the café is too steep to climb without proper shoes.
H. Kind regards, Emma"""

# ============================================================
# SPEAKING-P1 032701 - Curiosity & changing minds
# ============================================================
S1_032701 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "couldn't,find,lost,search,understand,explain,curious,about,maybe,see,if,change,mind,now",
        "questionSetID": "032701",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 couldn't find、I understand that、curious about、Maybe we can... to see if、changing my mind 等表达。",
        "questionSet": [
            {
                "content": "Tell us about a time you couldn't find something important. How did you feel and what did you do?",
                "ability": ["经历描述", "情感表达"],
                "explanation": "'I couldn't find my homework on the morning it was due. I felt so worried! I searched everywhere and finally found it under my bed.' 分享一次找不到东西的经历及你的感受。"
            },
            {
                "content": "When someone gives you an explanation for something, how do you show that you understand?",
                "ability": ["回应表达", "表达理解"],
                "explanation": "'I understand that it takes time to learn a new skill. Thank you for explaining it so clearly.' 展示你如何礼貌地回应他人的解释。"
            },
            {
                "content": "What is something you are really curious about right now? Why?",
                "ability": ["表达好奇", "表达观点"],
                "explanation": "'I'm curious about how birds know where to fly in winter. It seems like a miracle that they can travel so far and always find their way.' 分享一个让你好奇的事物。"
            },
            {
                "content": "Have you ever tried an experiment or test to see if something would work? What happened?",
                "ability": ["经历描述", "因果表达"],
                "explanation": "'Maybe we can put the plant in a dark cupboard to see if it still grows without sunlight. We tried it and after three days, the leaves turned yellow.' 分享一次测试或实验经历。"
            },
            {
                "content": "Tell us about a time you changed your mind about something. What made you change?",
                "ability": ["表达转变", "经历描述"],
                "explanation": "'I'm now changing my mind about spicy food. I used to hate it, but after trying my mum's mild curry last week, I discovered it can be really delicious.' 描述一次想法转变。"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "lost,search,understand,explain,curious,test,try,change,mind,grow,learn,wonder",
        "questionSetID": "032701",
        "textDesc": "请回答以下问题。继续使用本课的核心句型表达你的想法和经历。",
        "questionSet": [
            {
                "content": "What would you do if you couldn't find your way in a new place?",
                "ability": ["经历描述", "解决问题"],
                "explanation": "描述在陌生地方迷路时的应对方式。例如 'I couldn't find my way back to the hotel, so I asked a shopkeeper to help me.'"
            },
            {
                "content": "How do you feel when someone explains something you already know?",
                "ability": ["回应表达", "表达理解"],
                "explanation": "分享被重复解释时的感受及如何得体回应。例如 'I understand that you want to help, but I already learned this last term.'"
            },
            {
                "content": "What subject at school makes you the most curious? What do you want to learn more about?",
                "ability": ["表达好奇", "表达观点"],
                "explanation": "说说让你最好奇的科目。例如 'I'm curious about history because I want to know how people lived hundreds of years ago.'"
            },
            {
                "content": "Tell us about a time you changed your daily routine. What was different and why?",
                "ability": ["表达转变", "经历描述"],
                "explanation": "'I'm now changing my mind about waking up late. Last month I started getting up at six to read before school, and I feel so much better.'"
            }
        ]
    }
}
S1_032701_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 couldn't find、I understand that、curious about、Maybe we can... to see if、changing my mind 等表达。

【热词】
couldn't,find,lost,search,understand,curious,about,maybe,see,if,change,mind

【题目】
1. Tell us about a time you couldn't find something important. How did you feel and what did you do?
- 解析：'I couldn't find my homework on the morning it was due. I felt so worried!' 分享一次找不到东西的经历。

2. When someone gives you an explanation for something, how do you show that you understand?
- 解析：'I understand that it takes time to learn a new skill.' 展示你如何礼貌地回应解释。

3. What is something you are really curious about right now? Why?
- 解析：'I'm curious about how birds know where to fly in winter.' 分享让你好奇的事物。

4. Have you ever tried an experiment or test to see if something would work? What happened?
- 解析：'Maybe we can put the plant in a dark cupboard to see if it still grows.' 分享测试经历。

5. Tell us about a time you changed your mind about something. What made you change?
- 解析：'I'm now changing my mind about spicy food. I used to hate it, but...' 描述想法转变。"""
S1_032701_T2 = """【题目描述】
请回答以下问题。继续使用本课的核心句型表达你的想法和经历。

【热词】
lost,search,understand,explain,curious,test,try,change,mind,grow,learn

【题目】
1. What would you do if you couldn't find your way in a new place?
- 解析：描述在陌生地方迷路时的应对方式。

2. How do you feel when someone explains something you already know?
- 解析：分享被重复解释时的感受及如何得体回应。

3. What subject at school makes you the most curious? What do you want to learn more about?
- 解析：说说让你最好奇的科目及原因。

4. Tell us about a time you changed your daily routine. What was different and why?
- 解析：分享一次改变日常习惯的经历和感受。"""

# ============================================================
# WRITING 032801 - Problem-solving & asking for help
# ============================================================
W_032801 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "032801",
        "textDesc": "Your group's science project has suddenly stopped working and you need the teacher's help. Write an email to Miss Green explaining the problem and asking for advice.<br>Put these sentences in order to make a clear problem-solving email.",
        "optionSetList": [
            "Dear Miss Green,",
            "We need help because our science project has suddenly stopped working.",
            "What are we going to do now without the main part?",
            "Maybe we can borrow some tools from the art room to fix it.",
            "I've had this old robot kit since my last birthday, but I've never opened it before.",
            "It is a great idea that we thought of at the very last minute.",
            "Gratefully, Tom"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用", "问题解决｜求助与建议"],
        "explanation": "按求助邮件的逻辑：称呼→陈述问题→表达困惑→提出初步方案→提供备选资源→补充背景→署名。考察We need help because/What are we going to/Maybe we can/I've had... since.../It is a...idea that...等句型。C级体现在问题诊断-方案提议-资源调用的多层次思维组织。"
    },
    "second": {}
}
W_032801_T1 = """【题目描述】
Your group's science project has suddenly stopped working and you need the teacher's help. Write an email to Miss Green explaining the problem and asking for advice.
Put these sentences in order to make a clear problem-solving email.

【段落列表】
A. Dear Miss Green,
B. We need help because our science project has suddenly stopped working.
C. What are we going to do now without the main part?
D. Maybe we can borrow some tools from the art room to fix it.
E. I've had this old robot kit since my last birthday, but I've never opened it before.
F. It is a great idea that we thought of at the very last minute.
G. Gratefully, Tom"""

# ============================================================
# SPEAKING-P2 032801 - Challenges & habits
# ============================================================
S2_032801 = {
    "first": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "too,much,stop,started,right,after,spent,a lot,time,homework,game,test,challenge,habit",
        "questionSetID": "032801",
        "textDesc": "Here are some pictures about challenges and habits. What do you think about these situations?",
        "imageDesc": "Four images show children dealing with challenges and daily habits: 1st: A child sits at a desk piled with books and homework, looking anxious. 2nd: A child plays video games while the clock shows it is very late at night. 3rd: A child holds a test paper with a failing mark, wiping tears from the eyes. 4th: A group of children sit together in the library discussing a study plan.",
        "textImage": "032801-00.png",
        "questionSet": [
            {
                "content": "Have you ever felt that your homework was just too much? What did you do?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'This is too much homework for one night!' 描述一次你觉得任务太多的时候，以及你是怎么处理的。例如 'I felt stressed, so I made a list and finished the hardest subjects first.'"
            },
            {
                "content": "Have you ever done something that you just couldn't stop doing? What was it?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'Last weekend, I started reading a mystery book and I just couldn't stop until I finished it at midnight.' 分享一次你停不下来的经历。"
            },
            {
                "content": "When did a difficult situation start for you? What happened right after?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'It started right after I joined the advanced maths class. Everything became harder so quickly.' 描述困难开始的时刻及之后发生的事。"
            },
            {
                "content": "What have you and your friends spent a lot of time doing together? Was it worth it?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'We've spent a lot of time practising for the school play. It was tiring but completely worth it when we saw the audience clapping.' 分享投入大量时间的经历及收获。"
            },
            {
                "content": "What do you do when you find a problem too difficult to solve alone?",
                "ability": ["句型组织", "解决问题"],
                "explanation": "分享面对困难时的策略。例如 'When a problem is too difficult, I first try to break it into smaller parts. If I still can't do it, I ask my older sister or my teacher for help.'"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_topic",
        "asrPrompt": "too,much,stop,started,after,spent,time,change,habit,plan,help,future,improve",
        "questionSetID": "032801",
        "textDesc": "Now look at these pictures again. Think about how to change bad habits and build better ones.",
        "imageDesc": "Same images as above: children dealing with challenges and daily habits.",
        "textImage": "032801-01.png",
        "questionSet": [
            {
                "content": "What bad habit do you wish you could stop doing? Why?",
                "ability": ["句型组织", "表达反思"],
                "explanation": "'I just couldn't stop checking my phone before bed. It made me sleep very late and feel tired the next morning.'"
            },
            {
                "content": "What good habit did you start right after learning something new?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'It started right after our health class. I began drinking more water every day instead of juice.'"
            },
            {
                "content": "What is something you've spent a lot of time learning? Are you proud of it?",
                "ability": ["句型组织", "经历描述"],
                "explanation": "'We've spent a lot of time learning to play the guitar as a band. We are not perfect yet, but we are getting better.'"
            },
            {
                "content": "How do you feel when there is too much pressure from school or family?",
                "ability": ["句型组织", "情感表达"],
                "explanation": "分享面对压力时的感受和应对方式。例如 'When there is too much pressure, I talk to my mum about it and she always helps me feel calmer.'"
            },
            {
                "content": "What advice would you give to a younger student about managing time?",
                "ability": ["句型组织", "表达建议"],
                "explanation": "给学弟学妹一些时间管理建议。例如 'Don't do all your homework at the last minute. Spend a little time each day, and you will feel much less stressed.'"
            }
        ]
    }
}
S2_032801_T1 = """【题目描述】
Here are some pictures about challenges and habits. What do you think about these situations?

【热词】
too,much,stop,started,right,after,spent,lot,time,homework,game,test,challenge

【图片描述】
Four images show children dealing with challenges and daily habits: 1st: A child sits at a desk piled with books and homework, looking anxious. 2nd: A child plays video games while the clock shows it is very late at night. 3rd: A child holds a test paper with a failing mark, wiping tears from the eyes. 4th: A group of children sit together in the library discussing a study plan.

【题目】
1. Have you ever felt that your homework was just too much? What did you do?
- 解析：'This is too much homework for one night!' 描述一次你觉得任务太多的时候及应对方式。

2. Have you ever done something that you just couldn't stop doing? What was it?
- 解析：分享一次你停不下来的经历。

3. When did a difficult situation start for you? What happened right after?
- 解析：'It started right after I joined the advanced maths class.' 描述困难开始的时刻。

4. What have you and your friends spent a lot of time doing together? Was it worth it?
- 解析：'We've spent a lot of time practising for the school play.' 分享投入大量时间的经历。

5. What do you do when you find a problem too difficult to solve alone?
- 解析：分享面对困难时的策略。"""
S2_032801_T2 = """【题目描述】
Now look at these pictures again. Think about how to change bad habits and build better ones.

【热词】
too,much,stop,started,after,spent,time,change,habit,plan,help,future

【图片描述】
Same images as above: children dealing with challenges and daily habits.

【题目】
1. What bad habit do you wish you could stop doing? Why?
- 解析：分享你想改变的一个坏习惯。

2. What good habit did you start right after learning something new?
- 解析：'It started right after our health class. I began drinking more water.'

3. What is something you've spent a lot of time learning? Are you proud of it?
- 解析：分享你花了很多时间学习的事情。

4. How do you feel when there is too much pressure from school or family?
- 解析：分享面对压力时的感受和应对方式。

5. What advice would you give to a younger student about managing time?
- 解析：给学弟学妹一些时间管理建议。"""
S2_032801_PIC = '[1-组图]:{"prompt_2":"黑白线条图:一个孩子坐在堆满书本和作业的桌前，双手抱头表情焦虑","prompt_3":"黑白线条图:一个孩子坐在沙发上拿着游戏机玩，墙上的时钟指向深夜十一点","prompt_4":"黑白线条图:一个孩子拿着不及格的试卷，脸上挂着泪水，表情沮丧","prompt_5":"黑白线条图:一组孩子围坐在图书馆的桌旁一起讨论学习计划"}'

# ============================================================
# WRITING 032901 - Celebration & emotions
# ============================================================
W_032901 = {
    "first": {
        "category": "writing", "type": "writing_email",
        "questionSetID": "032901",
        "textDesc": "You are at your mum's birthday party and having a wonderful time. Write an email to your friend Sophie to describe the party, the people, and the happy mood.<br>Put these sentences in order to make a warm and descriptive email.",
        "optionSetList": [
            "Dear Sophie,",
            "My little sister loves to dance whenever music starts playing.",
            "She doesn't care if anyone is watching her spin around.",
            "Mum will be so happy that everyone she loves came to her party.",
            "I can't stay out too late because I have a maths test tomorrow morning.",
            "Dad seems in a wonderful mood tonight.",
            "Everyone is wearing their best party clothes.",
            "With love, Jessica"
        ],
        "answerSet": [0, 1, 2, 3, 4, 5, 6, 7],
        "ability": ["短消息写作｜邮件/便条", "衔接与连贯｜连词使用", "描述性写作｜场景与情绪"],
        "explanation": "按聚会描述的逻辑：称呼→妹妹的动态→不care→妈妈的心情→自己的限制→爸爸的状态→大家穿着→署名。考察loves to/doesn't care/will be so happy that/can't...because/seems in a...mood/is wearing等句型。C级体现在多人物平行描述和情感状态的切换。"
    },
    "second": {}
}
W_032901_T1 = """【题目描述】
You are at your mum's birthday party and having a wonderful time. Write an email to your friend Sophie to describe the party, the people, and the happy mood.
Put these sentences in order to make a warm and descriptive email.

【段落列表】
A. Dear Sophie,
B. My little sister loves to dance whenever music starts playing.
C. She doesn't care if anyone is watching her spin around.
D. Mum will be so happy that everyone she loves came to her party.
E. I can't stay out too late because I have a maths test tomorrow morning.
F. Dad seems in a wonderful mood tonight.
G. Everyone is wearing their best party clothes.
H. With love, Jessica"""

# ============================================================
# SPEAKING-P1 032901 - Teamwork & communication
# ============================================================
S1_032901 = {
    "first": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "let's,suggest,activity,hope,can,achieve,talk,to,solve,problem,use,method,tool,team",
        "questionSetID": "032901",
        "textDesc": "请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 Let's、We hope that...can...、try to talk to、can use 等表达。",
        "questionSet": [
            {
                "content": "How do you suggest a fun activity to your friends? What do you say?",
                "ability": ["表达建议", "邀请表达"],
                "explanation": "'Let's go to the park after school and fly our kites!' 展示你如何邀请朋友一起做有趣的事。也可以用 'Why don't we...' 或 'How about...' 来使邀请更加自然。"
            },
            {
                "content": "What do you hope your class or team can achieve together this year?",
                "ability": ["表达期望", "表达观点"],
                "explanation": "'We hope that our class can win the school sports day this year. We have been practising every morning and getting stronger together.' 分享你对班级或团队的期望。"
            },
            {
                "content": "When there is a problem in your group, how do you try to talk to your classmates about it?",
                "ability": ["协商表达", "解决问题"],
                "explanation": "'We try to talk to each other calmly and listen to everyone's ideas before making a decision.' 描述你们如何通过沟通解决问题。"
            },
            {
                "content": "What tools or methods can you use to work better as a team?",
                "ability": ["表达建议", "表达观点"],
                "explanation": "'We can use a shared calendar to plan our tasks and set clear deadlines. We can also use group chats to stay in touch after school.' 分享提高团队效率的工具或方法。"
            }
        ]
    },
    "second": {
        "category": "speaking", "type": "speaking_qa",
        "asrPrompt": "let's,organise,event,hope,can,improve,talk,solve,disagreement,use,technology,share,ideas",
        "questionSetID": "032901",
        "textDesc": "请回答以下问题。继续使用本课的核心句型，分享更多关于合作与交流的想法。",
        "questionSet": [
            {
                "content": "Let's say you are organising a class party. What would you suggest doing first?",
                "ability": ["表达建议", "计划描述"],
                "explanation": "'Let's first make a list of everything we need, then divide the tasks among everyone.' 描述你组织活动的第一步。"
            },
            {
                "content": "What do you hope that the students in your school can do to help the environment?",
                "ability": ["表达期望", "表达观点"],
                "explanation": "'We hope that every student can bring a reusable water bottle and stop buying plastic ones. Small changes can make a big difference.'"
            },
            {
                "content": "Have you ever had to try to talk to someone about a disagreement? How did it go?",
                "ability": ["协商表达", "经历描述"],
                "explanation": "分享一次解决分歧的沟通经历。例如 'We try to talk to each other after the argument. I said how I felt, and my friend said how she felt, and then we understood each other better.'"
            },
            {
                "content": "What online tools can you use to study together with classmates outside of school?",
                "ability": ["表达建议", "表达观点"],
                "explanation": "'We can use shared documents to work on the same project at the same time, even when we are at our own homes.' 分享线上协作学习的工具和方法。"
            }
        ]
    }
}
S1_032901_T1 = """【题目描述】
请回答以下问题。用清晰、完整的英文语句进行回答，尝试使用 Let's、We hope that...can...、try to talk to、can use 等表达。

【热词】
let's,suggest,activity,hope,achieve,talk,solve,problem,use,method,tool,team

【题目】
1. How do you suggest a fun activity to your friends? What do you say?
- 解析：'Let's go to the park after school and fly our kites!' 展示你如何邀请朋友一起做有趣的事。

2. What do you hope your class or team can achieve together this year?
- 解析：'We hope that our class can win the school sports day this year.' 分享对班级的期望。

3. When there is a problem in your group, how do you try to talk to your classmates about it?
- 解析：'We try to talk to each other calmly and listen to everyone's ideas.' 描述通过沟通解决问题。

4. What tools or methods can you use to work better as a team?
- 解析：'We can use a shared calendar to plan our tasks.' 分享提高团队效率的方法。"""
S1_032901_T2 = """【题目描述】
请回答以下问题。继续使用本课的核心句型，分享更多关于合作与交流的想法。

【热词】
let's,organise,event,hope,improve,talk,solve,disagreement,use,technology,share,ideas

【题目】
1. Let's say you are organising a class party. What would you suggest doing first?
- 解析：'Let's first make a list of everything we need, then divide the tasks.' 描述组织活动。

2. What do you hope that the students in your school can do to help the environment?
- 解析：'We hope that every student can bring a reusable water bottle.' 分享环保期望。

3. Have you ever had to try to talk to someone about a disagreement? How did it go?
- 解析：分享一次解决分歧的沟通经历。

4. What online tools can you use to study together with classmates outside of school?
- 解析：分享线上协作学习的工具和方法。"""

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

    records = [
        # (label, table, QSID, jsonData, 题目1, 题目2, 图片描述, kw1, kw2)
        # Writing records
        ("写作 032501", "tblszuk1TeToofBF", "032501", W_032501, W_032501_T1, "", "", "", ""),
        ("写作 032601", "tblszuk1TeToofBF", "032601", W_032601, W_032601_T1, "", "", "", ""),
        ("写作 032701", "tblszuk1TeToofBF", "032701", W_032701, W_032701_T1, "", "", "", ""),
        ("写作 032801", "tblszuk1TeToofBF", "032801", W_032801, W_032801_T1, "", "", "", ""),
        ("写作 032901", "tblszuk1TeToofBF", "032901", W_032901, W_032901_T1, "", "", "", ""),
        # Speaking P1 records
        ("口语-P1 032501", "tblRGv7k4WH58Jgq", "032501", S1_032501, S1_032501_T1, S1_032501_T2, "",
         "however,sooner,later,depending,used,change,mind,weather,plan",
         "however,sooner,later,depending,used,opinion,technology,future"),
        ("口语-P1 032701", "tblRGv7k4WH58Jgq", "032701", S1_032701, S1_032701_T1, S1_032701_T2, "",
         "couldn't,find,lost,search,understand,curious,maybe,see,if,change,mind",
         "lost,search,understand,explain,curious,test,change,mind,grow"),
        ("口语-P1 032901", "tblRGv7k4WH58Jgq", "032901", S1_032901, S1_032901_T1, S1_032901_T2, "",
         "let's,suggest,hope,achieve,talk,solve,problem,use,method,team",
         "let's,organise,hope,improve,talk,solve,disagreement,use,technology"),
        # Speaking P2 records
        ("口语-P2 032601", "tblGoWYBmVI0IrvQ", "032601", S2_032601, S2_032601_T1, S2_032601_T2, S2_032601_PIC, "", ""),
        ("口语-P2 032801", "tblGoWYBmVI0IrvQ", "032801", S2_032801, S2_032801_T1, S2_032801_T2, S2_032801_PIC, "", ""),
    ]

    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 "口语-P1" in label:
            fields["题目1 完整配置" if False else "题目1"] = t1
        if t2:
            fields["题目2" if "口语-P2" not in label else "题目2"] = t2
        if pic:
            fields["图片描述"] = pic
        if kw1:
            fields["题目1热词"] = kw1
        if kw2:
            fields["题目2热词"] = kw2

        # Fix field names based on table
        if tid == "tblszuk1TeToofBF":  # Writing P1
            fields["题目1 完整配置"] = fields.pop("题目1")
            if "题目2" in fields: del fields["题目2"]
        elif tid == "tblRGv7k4WH58Jgq":  # Speaking P1
            pass  # field names ok
        elif tid == "tblGoWYBmVI0IrvQ":  # Speaking P2
            pass

        resp = create(token, tid, fields)
        code = resp.get("code")
        if code == 0:
            rid = resp["data"]["record"]["record_id"]
            print(f"[✅] {label} → {rid}")
            results.append((label, qsid, rid, True))
        else:
            print(f"[❌] {label}: {resp.get('msg')}")
            results.append((label, qsid, "FAIL", False))
        time.sleep(0.3)

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

if __name__ == "__main__":
    main()
