1 Star 0 Fork 0

Eugene/relingo-vocabulary

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
getVocabulary.py 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
egu0 提交于 2024-02-15 20:04 . init
import requests
import json
import time
import os
def get_vocabulary(level_id: str):
body = {"id": level_id, "type": "builtin"}
response = requests.post(
"https://api.relingo.net/api/getVocabulary", json=body)
response.raise_for_status()
return response.json()
def process(level_id: str):
vocabulary = get_vocabulary(level_id)
if 'data' in vocabulary and 'words' in vocabulary['data']:
words = vocabulary['data']['words']
print(f'size of {level_id}: {len(words)}')
sorted_words = sorted(words)
# write json file in dated directory
cur_time = time.localtime()
date_named_dir = f'{cur_time.tm_year}-{cur_time.tm_mon}-{cur_time.tm_mday}'
if not os.path.exists(date_named_dir):
os.makedirs(date_named_dir)
with open(f'{date_named_dir}/level-{level_id}.json', 'w') as json_file:
json.dump(sorted_words, json_file, indent=4, ensure_ascii=True)
# all levels' dictionary names
levels = ['Beginner', 'Intermediate', 'Advanced', 'Proficient',
'GRE', 'IELTS', 'TOEFL', 'SAT', 'CET4', 'CET6', 'KaoYan',
'GMAT', 'Medical']
for level in levels:
process('relingo-' + level)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/egu0/relingo-vocabulary.git
[email protected]:egu0/relingo-vocabulary.git
egu0
relingo-vocabulary
relingo-vocabulary
main

搜索帮助