# -*- coding:utf-8 -*-
#
import json 
import time
from functools import wraps
from random import shuffle,sample,randint
from threading import Thread
from concurrent.futures import ThreadPoolExecutor,wait

import httpx
import requests
from pydantic import BaseModel
from typing import List


product_adress = "http://111.231.167.191" 
test_address = "http://111.231.167.191:8004" 
test_address2 = "http://111.231.167.191:8003" 

local_adress = "http://127.0.0.1:9000" 

use_address = test_address 


class DifficultSentence(BaseModel):
    english: str
    chinese: str

class Candidate(BaseModel):
    label: str
    text: str
    isRight: int

class Question(BaseModel):
    trunk: str
    analysis: str
    candidates: List[Candidate]

class Article(BaseModel):
    difficultSentences: List[DifficultSentence]
    usedMeanIds: List[int]
    questions: List[Question]
    englishArticle: str
    chineseArticle: str
    allWordAmount: int

class ArticleData(BaseModel):
    articles: List[Article]


def time_use(fn):
    @wraps(fn)
    def cc(*args, **kwargs): 
        f_time = time.time()
        res = fn(*args, **kwargs)

        cha = round(time.time() - f_time, 3)
        if cha > 0.1:
            print(f'函数:{fn.__name__} 一共用时', cha, '秒')
        return res 

    return cc


def test_connect():
    """连接测试"""
    try:
        r = requests.post(use_address)
        assert r.text == 'hello world'
        r = requests.get(use_address)
        assert r.text == 'hello world'
        print("测试连接成功")
    except AssertionError:
        print("测试连接失败")


def get_article():
    """同时检验article接口和query_oss_file接口"""
    json_data = {"meaning_ids": [300751, 300756, 300757, 300758, 300454, 302096, 302102], "callback_url": "http://localhost/callback",
                 "student_stage": 1, "vocabulary": 700, "class_id": 123456}

    r = requests.post(f"{use_address}/article", json=json_data)
   
    key = r.json()['key']
    time.sleep(120)
    query_file_content(key)


def query_file_content(key):
    json_data = {"key": key}
    try:
        r = requests.post(f"{use_address}/query_oss_file", json=json_data)
        r.raise_for_status() 
        response_data = r.json()
        assert response_data['wordCount'] > 0, "词数为0"
    except requests.RequestException as e:
        print(f"请求失败: {e}")
    except json.JSONDecodeError as e:
        print(f"JSON解析错误: {e}")
    except AssertionError as e:
        print(f"断言错误: {e}")
    except Exception as e:
        print(f"未知错误: {e}")


def get_audio():
    word = "cat"
    r1 = requests.post(f"{use_address}/tts", json={"text": word, "type": 0}) 
    r2 = requests.post(f"{use_address}/tts", json={"text": word, "type": 2}) 
    r3 = requests.post(f"{use_address}/tts", json={"text": word, "type": 1}) 
    assert r1.json()['code'] == 200
    assert r2.json()['code'] == 200
    assert r3.status_code == 200


@time_use
def get_article2():
    json_data = {"words": [
        {'spell': 'term', 'meaning': '学期'}, {'spell': 'ordinary', 'meaning': '平常的, 普通的, 一般的'},
        {'spell': 'discussion', 'meaning': '讨论, 谈论'}, {'spell': 'shine', 'meaning': '照耀, 发光, 闪耀'},
        {'spell': 'million', 'meaning': '百万'}, {'spell': 'greet', 'meaning': '问候'}
    ], "take_count": 1, "student_stage": 3, "demo_name": "测试项目"}

    r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
    r_json = r.json()
    try:
        assert len(r_json['articles']) == 1
        return r_json
    except Exception as e:
        print("春笋文章reading-comprehension错误", e)
        print("错误数据", r_json)


@time_use
def get_article2_1():
    """新的获取文章"""
    core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
                       {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
                       {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
                       {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
                       {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
                       {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
                       {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
                       {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
                       {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
                       {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
                       {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
                       {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
                       {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
                       {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
                       {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
                       {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
                       {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
                       {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
                       {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
                       {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
                       {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
                       {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
                       {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
                       {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
                       {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
                       {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
                       {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
                       {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
                       {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
                       {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
                       {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
                       {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
                       {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
                       {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
                       {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
                       {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
                       {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
                       {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
                       {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
                       {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
                       {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
                       {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
                       {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
                       {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063},
                       {'spell': 'carry', 'meaning': '携带', 'word_id': 803106, 'meaning_id': 460, 'serial': 313},
                       {'spell': 'area', 'meaning': '领域', 'word_id': 765328, 'meaning_id': 572, 'serial': 388},
                       {'spell': 'lie', 'meaning': '说谎, 谎言', 'word_id': 963062, 'meaning_id': 602, 'serial': 409},
                       {'spell': 'company', 'meaning': '陪伴', 'word_id': 822886, 'meaning_id': 642, 'serial': 433},
                       {'spell': 'else', 'meaning': '别的, 另外的, 其他的', 'word_id': 869964, 'meaning_id': 654, 'serial': 443},
                       {'spell': 'cover', 'meaning': '覆盖', 'word_id': 834220, 'meaning_id': 687, 'serial': 472},
                       {'spell': 'effect', 'meaning': '引起', 'word_id': 866665, 'meaning_id': 709, 'serial': 486},
                       {'spell': 'design', 'meaning': '设计, 计划', 'word_id': 848239, 'meaning_id': 714, 'serial': 490},
                       {'spell': 'century', 'meaning': '世纪, 百年', 'word_id': 806994, 'meaning_id': 725, 'serial': 498},
                       {'spell': 'above', 'meaning': '上面，之上，超过', 'word_id': 745232, 'meaning_id': 736, 'serial': 508},
                       {'spell': 'sign', 'meaning': '手势, 符号, 签名', 'word_id': 1089428, 'meaning_id': 752, 'serial': 517},
                       {'spell': 'remain', 'meaning': '保持不变', 'word_id': 1062570, 'meaning_id': 774, 'serial': 530},
                       {'spell': 'line', 'meaning': '线, 画线', 'word_id': 964670, 'meaning_id': 777, 'serial': 532},
                       {'spell': 'likely', 'meaning': '有可能的', 'word_id': 964153, 'meaning_id': 781, 'serial': 534},
                       {'spell': 'fail', 'meaning': '失败, 不及格', 'word_id': 882595, 'meaning_id': 787, 'serial': 540},
                       {'spell': 'control', 'meaning': '控制, 支配, 操纵', 'word_id': 829355, 'meaning_id': 794, 'serial': 545},
                       {'spell': 'power', 'meaning': '权力, 力量', 'word_id': 1038172, 'meaning_id': 800, 'serial': 549},
                       {'spell': 'reply', 'meaning': '回答, 回应, 答辩', 'word_id': 1063609, 'meaning_id': 817, 'serial': 563},
                       {'spell': 'unless', 'meaning': '除非, 如果不', 'word_id': 1150079, 'meaning_id': 822, 'serial': 567},
                       {'spell': 'offer', 'meaning': '提出, 提供', 'word_id': 1005291, 'meaning_id': 824, 'serial': 569}
                       ]
    shuffle(core_words_list)
    core_words_chiose_list = sample(core_words_list,15)
    json_data = {'core_words': core_words_chiose_list,
                 'take_count': 1, 'student_stage': 2, 'demo_name': '春笋英语', "exercise_id": randint(100,999),
                 "article_length": 220, "reading_level": 25}

    r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
    r_json = r.json()
    try:
        return r_json
    except Exception as e:
        print("春笋文章reading-comprehension错误", e)
        print("错误数据", r_json)

@time_use
def get_article2_2():
    """测试通过requests来直接访问openai"""
    core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
                       {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
                       {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
                       {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
                       {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
                       {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
                       {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
                       {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
                       {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
                       {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
                       {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
                       {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
                       {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
                       {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
                       {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
                       {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
                       {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
                       {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
                       {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
                       {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
                       {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
                       {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
                       {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
                       {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
                       {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
                       {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
                       {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
                       {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
                       {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
                       {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
                       {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
                       {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
                       {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
                       {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
                       {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
                       {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
                       {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
                       {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
                       {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
                       {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
                       {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
                       {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
                       {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
                       {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063}
                       ]
    shuffle(core_words_list)
    core_words_chiose_list = sample(core_words_list,15)
    core_words_meaning_str = "; ".join([f"[{i['meaning_id']}  {i['spell']} {i['meaning']}]" for i in core_words_chiose_list])

    question = f"""下面我会为你提供一组数据，[单词组]（里面包含词义id，英语单词，中文词义），请根据这些单词的中文词义，生成一篇带中文翻译的考场英语文章，英语文章和中文翻译要有[标题]。注意这个单词有多个词义时，生成的英语文章一定要用提供的中文词义。并挑选一句复杂的句子和其中文翻译，放入difficultSentences。英语文章，放入"englishArticle"中。中文翻译，放入"chineseArticle"中。最终文中使用到的单词id放入"usedMeanIds"中。4个选择题，放入questions字段。questions结构下有4个选择题对象，其中trunk是[英语]问题文本，analysis是[中文]的问题分析，candidates是4个ABCD选项，内部有label是指选项序号A B C D ，text是[英语]选项文本，isRight是否正确答案1是正确0是错误。

要求:
1.必须用提供的这个词义的单词，其他单词使用最简单最容易没有难度的单词。文章整体非常简洁，通俗易懂，适合初学者，刚入门，单词全是最常见的，语句通顺即可。选择题难度尽可能简单，参考中国小学生水平
2.优先保证文章语句通顺，意思不要太生硬。不要为了使用特定的单词，造成文章语义前后不搭，允许不使用个别词义。
3.文章中使用提供单词，一定要和提供单词的中文词义匹配，尤其是一词多义时，务必使用提供单词的词义。必须要用提供单词的词义。如果用到的词义与提供单词词义不一致，请不要使用这个单词。
4.生成的文章要求320词左右，可以用\\n\\n字符分段，一般3-4个段落左右。第一段是文章标题。
5.允许不使用[单词组]的个别单词，优先保证文章整体意思通顺连贯和故事完整。
6.注意回复字段的中英文，englishArticle是英文，chineseArticle是中文，其中trunk是英文，analysis是中文，text是英文。

提供[单词组]：{core_words_meaning_str}
"""

   
   
    url = 'http://170.106.108.95/v1/chat/completions'

   
    headers = {
        "Authorization": f"Bearer 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",
        "Content-Type": "application/json"
    }

   
    data = {
        "model": "gpt-4.1", 
        "messages": [
           
            {"role": "user", "content": question}
        ],
        "max_tokens": 8000, 
        "temperature": 1.2, 
        "n":4,
        "response_format": {'type': 'json_schema', 'json_schema': {'name': 'Article', 'schema': {'$defs': {'Candidate': {'properties': {'label': {'title': 'Label', 'type': 'string'}, 'text': {'title': 'Text', 'type': 'string'}, 'isRight': {'title': 'Isright', 'type': 'integer'}}, 'required': ['label', 'text', 'isRight'], 'title': 'Candidate', 'type': 'object'}, 'DifficultSentence': {'properties': {'english': {'title': 'English', 'type': 'string'}, 'chinese': {'title': 'Chinese', 'type': 'string'}}, 'required': ['english', 'chinese'], 'title': 'DifficultSentence', 'type': 'object'}, 'Question': {'properties': {'trunk': {'title': 'Trunk', 'type': 'string'}, 'analysis': {'title': 'Analysis', 'type': 'string'}, 'candidates': {'items': {'$ref': '#/$defs/Candidate'}, 'title': 'Candidates', 'type': 'array'}}, 'required': ['trunk', 'analysis', 'candidates'], 'title': 'Question', 'type': 'object'}}, 'properties': {'difficultSentences': {'items': {'$ref': '#/$defs/DifficultSentence'}, 'title': 'Difficultsentences', 'type': 'array'}, 'usedMeanIds': {'items': {'type': 'integer'}, 'title': 'Usedmeanids', 'type': 'array'}, 'questions': {'items': {'$ref': '#/$defs/Question'}, 'title': 'Questions', 'type': 'array'}, 'englishArticle': {'title': 'Englisharticle', 'type': 'string'}, 'chineseArticle': {'title': 'Chinesearticle', 'type': 'string'}, 'allWordAmount': {'title': 'Allwordamount', 'type': 'integer'}}, 'required': ['difficultSentences', 'usedMeanIds', 'questions', 'englishArticle', 'chineseArticle', 'allWordAmount'], 'title': 'Article', 'type': 'object'}}}
    }

   
    try:
        response = httpx.post(url, headers=headers, json=data,timeout=300)
        return response.json()
    except Exception as e:
        print(f"错误：{type(e).__name__}: {e}")




def download_word():
    from make_docx_demo.data import test_json2
    params = {"document_format": 2, "scanpage_format": 1}

    r = requests.post(f"{use_address}/make_word/vocabulary_assault", params=params, json=test_json2)
    r.raise_for_status()
    suffix = {1: "docx", 2: "pdf"}[params['document_format']]
    with open(f"test.{suffix}", "wb") as f:
        f.write(r.content)


def spoken_language():
    url = f"{use_address}/spoken_language"
    with open(r"1.mp3", "rb") as f:
        audio_data = {'file': ('file.bin', f, 'application/octet-stream')}
        data = {"text": "You must study to be frank with the world"}
        r1 = requests.post(url, data=data, files=audio_data)
    assert r1.json()['code'] == 0

    data = {"text": "apple Life is like a box of chocolates， you never know what you're gonna",
            "url": "https://yunzhixue.blob.core.chinacloudapi.cn/download/ttsmaker-file-2025-1-13-10-47-47.mp3"}
    r2 = requests.post(url, data=data)
    assert r2.json()['code'] == 0


@time_use
def get_article3():
    json_data = {"words": [
        {'spell': 'term', 'meaning': '学期'}, {'spell': 'ordinary', 'meaning': '平常的, 普通的, 一般的'},
        {'spell': 'discussion', 'meaning': '讨论, 谈论'}, {'spell': 'shine', 'meaning': '照耀, 发光, 闪耀'},
        {'spell': 'million', 'meaning': '百万'}, {'spell': 'greet', 'meaning': '问候'}
    ], "take_count": 1, "student_stage": 3, "demo_name": "测试项目"}

    r = requests.post(f"{use_address}/article/reading-comprehension/deepseek", json=json_data)
    r_json = r.json()
    try:
        assert r_json['articles'][0]["english"]
        assert r_json['articles'][0]["difficultSentences"]
        assert r_json['articles'][0]["questions"]
        assert r_json['articles'][0]["allWordAmount"] > 10
        return r_json
    except Exception as e:
        print("deepseek生成文章出错", e)
        print(r_json)


@time_use
def run_all_test_cese():
    test_connect() 

    get_audio() 
    spoken_language() 
    download_word() 
    get_article2_1() 
    article_annotation() 

   
   


@time_use
def multi_request():
    with ThreadPoolExecutor(max_workers=150) as executor:
       
        futures = [executor.submit(get_article2_1) for _ in range(100)]
       

       
        wait(futures)
        print("完成等待")
        f = open("result.txt",'w',encoding='utf-8')

        try:
            for index,future in enumerate(futures,start=1):
                f.write(str(future.result()) + '\n') 
        except Exception as e:
            print(f"错误：{type(e).__name__}: {e}")
        finally:
            f.close()

@time_use
def article_annotation():
    text = """The expression, “Everybody’s doing it,” is very much at the center of the concept of peer pressure. It is a social influence applied on an individual in order to get that person to act or believe in a(n) ____1____ way as a larger group. 
This influence can be negative or positive, and can exist in both large and small groups.People are social creatures by nature, and so it is hardly ____2____ that some part of their self-respect comes from the approval of others. This instinct explains why the approval of peers, and the fear of ____3____, is such a powerful force in many people’s lives. This instinct drives people to dress one way at home and another way at work, or to answer a simple “fine” when a stranger asks “How are you?” even if it is not necessarily true. There is a(n) ____4____ aspect to this: It helps society to function efficiently, and encourages a general level of self-discipline that ____5____ day-to-day interaction between people.
For certain individuals, seeking social acceptance is so important that it becomes a(n) ____6____: in order to satisfy the desire, they may go so far as to ____7____ their sense of right and wrong. Teens and young adults may feel forced to use drugs, or join gangs that ____8____ criminal behavior. Mature adults may sometimes feel ____9____ to cover up illegal activity at the company where they work, or end up in debt because they are unable to hold back the desire to buy a house or car that they can’t afford in an effort to ____10____ the peers.
However, peer pressure is not always negative. A student whose friends are good at contests may be ____11____ to work harder and get good grades. Players on a sports team may feel driven to play harder in order to help the team win. This type of ____12____ can also get a friend off drugs, or to help an adult take up a good habit or drop a bad one.
Although peer pressure is sometimes quite obvious, it can also be so ____13____ that a person may not even notice that it is affecting his or her behavior. For this reason, when making important decisions, simply going with a(n) ____14____ is risky. Instead, people should seriously consider why they feel drawn to taking a particular action, and whether the real ____15____ is simply that everyone else is doing the same thing."""

    json_data = {"english_text":"hello,please give me an apple.","split_blank":False} 
   
    r = requests.post(f"{use_address}/article/meaning/annotation", json=json_data)
    r_json = r.json()
    assert r.status_code == 200 and r_json.get("code")==200
   




if __name__ == '__main__':
   
   
   

   


   
   

   

   
    get_audio()

   