# -*- coding:utf-8 -*- """获取学段标准数据""" from cachetools import TTLCache, cached import requests from tools.loglog import logger, log_err_e cache = TTLCache(maxsize=100, ttl=86400) def get_standard_data(student_stage: int): if student_stage in cache: return cache[student_stage] url = "https://dcjxb.yunzhixue.cn/api-dev/standard/study" params = {"stage": student_stage} response = requests.get(url, params=params) if response.status_code == 200: data_obj = response.json()['data'] return_data = data_obj['totalVocabulary'], data_obj['readingAccuracy'], data_obj['readingLevel'], data_obj['readingSpeed'] cache[student_stage] = return_data return return_data if __name__ == '__main__': print(get_standard_data(3)) print(cache) print(1 in cache, 2 in cache, 3 in cache)