Skip to content

Commit

Permalink
feat:答题题库增加 TikuAdapter (#400)
Browse files Browse the repository at this point in the history
* feat:答题题库增加 TikuAdapter

* 移除测试输出日志代码,调整题目类型判断
  • Loading branch information
www12x2 authored Dec 6, 2024
1 parent da91c15 commit 945cf53
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
44 changes: 44 additions & 0 deletions api/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,47 @@ def load_token(self):
def _init_tiku(self):
self.load_token()

class TikuAdapter(Tiku):
# TikuAdapter题库实现 https://github.com/DokiDoki1103/tikuAdapter
def __init__(self) -> None:
super().__init__()
self.name = 'TikuAdapter题库'
self.api = ''

def _query(self, q_info: dict):
# 判断题目类型
if q_info['type'] == "single":
type = 0
elif q_info['type'] == 'multiple':
type = 1
elif q_info['type'] == 'completion':
type = 2
elif q_info['type'] == 'judgement':
type = 3
else:
type = 4

options = q_info['options']
res = requests.post(
self.api,
json={
'question': q_info['title'],
'options': options.split('\n'),
'type': type
},
verify=False
)
if res.status_code == 200:
res_json = res.json()
if bool(res_json['plat']):
logger.error("查询失败,返回:" + res.text)
return None
sep = "\n"
return sep.join(res_json['answer']['allAnswer'][0]).strip()
# else:
logger.error(f'{self.name}查询失败:\n{res.text}')
return None

def _init_tiku(self):
# self.load_token()
self.api = self._conf['url']
3 changes: 3 additions & 0 deletions config_template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ speed = 1
[tiku]
; 可选项 :
; 1. TikuYanxi(言溪题库 https://tk.enncy.cn/)
; 2. TikuAdapter(开源项目 https://github.com/DokiDoki1103/tikuAdapter)
provider=TikuYanxi
; 是否直接提交答题,填写false表示答完题后不提交而是保存,随后你可以自行前往学习通修改或提交
; 填写true表示直接提交,不保证正确率!不正确的填写会被视为false
; 对于那些需要解锁的章节,你必须要提交章节检测才能继续下一章节的学习,自行决定是否开启
submit=false
; 用于言溪题库的TOKEN,同样使用英文逗号隔开多个,会按顺序去使用
tokens=
; 用于TikuAdapter题库的url
url=
; 用于判断判断题对应的选项,不要留有空格,不要留有引号,逗号为英文逗号
true_list=正确,对,√,是
false_list=错误,错,×,否,不对,不正确

0 comments on commit 945cf53

Please sign in to comment.