Skip to content

Commit 9fdeec8

Browse files
committed
feat: 上传 ziantt 题库
1 parent 0a274ca commit 9fdeec8

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

bili-hardcore/client/ziantt.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from tools.request_b import session
2+
from tools.logger import logger
3+
4+
def save_question(json):
5+
'''
6+
保存题目信息
7+
{
8+
"qid": qid, // int类型
9+
"question": question, // 题面
10+
"ans_1": ans_1, // 无顺序限制,提交ans_text而非ans_hash
11+
"ans_2": ans_2,
12+
"ans_3": ans_3,
13+
"ans_4": ans_4,
14+
"answer": correct_answer, // 若已知正确答案提交正确的ans_text,未知请提交null
15+
"source": source, // int类型,与author字段二选一,以b站接口返回的实际内容为准
16+
"author": author, // str类型,与source字段二选一,以b站接口返回的实际内容为准
17+
"category": category // str类型,请传入单一类型id,如"2",如用户选择的是多个类型,不确定id请传入null
18+
}
19+
'''
20+
res = session.post('https://senior.ziantt.top/submit',
21+
json = json,
22+
headers={
23+
"User-Agent": "bili-hardcore Script Report",
24+
});
25+
# resp = res.json()
26+
# logger.info(resp)
27+
# if resp["status"] == "success":
28+
# logger.info("题库服务器提交成功")
29+
# elif resp["status"] == "exist":
30+
# logger.info("题目已存在")
31+
# else:
32+
# logger.info("题库服务器提交失败")

bili-hardcore/scripts/start_senior.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66

77
from config.config import model_choice
88
from scripts.check_config import clear_config
9+
from client.ziantt import save_question
10+
from time import sleep
911

1012
class QuizSession:
1113
def __init__(self):
1214
self.question_id = None
1315
self.answers = None
16+
self.question_json = None
1417
self.question_num = 0
1518
self.question = None
19+
self.current_score = 0
20+
self.category = None
21+
self.confirm = False
1622

1723
def start(self):
1824
"""开始答题会话"""
25+
print("我们正在构建一个硬核会员题库,您是否愿意上传答题信息帮助我们构建题库?")
26+
print("此操作仅会上传题目和题目对应的答案信息,并不会上传您的其他信息")
27+
confirm = input('是否授权上传本次答题内容?[1]是 [2]否: ')
28+
self.confirm = confirm == '1'
1929
try:
2030
while self.question_num < 100:
2131
if not self.get_question():
@@ -48,6 +58,13 @@ def start(self):
4858
if not self.submit_answer(result):
4959
logger.error("提交答案失败")
5060
return
61+
score = question_result().get('score');
62+
if self.current_score < score:
63+
logger.info("回答正确, 当前得分:{}".format(score))
64+
self.current_score = score
65+
self.upload_question(answer)
66+
else:
67+
logger.info("回答错误, 当前得分:{}".format(score))
5168
self.print_result()
5269
except KeyboardInterrupt:
5370
logger.info("答题会话已终止")
@@ -69,6 +86,7 @@ def get_question(self):
6986
return self.handle_verification()
7087

7188
data = question.get('data', {})
89+
self.question_json = data
7290
self.question = data.get('question')
7391
self.answers = data.get('answers', [])
7492
self.question_id = data.get('id')
@@ -96,6 +114,7 @@ def handle_verification(self):
96114
logger.info(f"ID: {cat.get('id')} - {cat.get('name')}")
97115
logger.info("tips: 输入多个分类ID请用 *英文逗号* 隔开,例如:1,2,3(最多三个分类)")
98116
ids = input('请输入分类ID: ')
117+
self.category = ids
99118
logger.info("获取验证码...")
100119
captcha_res = captcha_get()
101120
logger.info("请打开链接查看验证码内容:{}".format(captcha_res.get('url')))
@@ -109,7 +128,6 @@ def handle_verification(self):
109128
else:
110129
logger.error("验证失败")
111130
return False
112-
113131
except Exception as e:
114132
logger.error(f"验证过程发生错误: {str(e)}")
115133
return False
@@ -180,6 +198,26 @@ def print_result(self):
180198
except Exception as e:
181199
logger.error(f"获取答题结果失败: {str(e)}")
182200

201+
def upload_question(self, answer):
202+
# 保存题目
203+
if self.confirm:
204+
try:
205+
question_submit_content = {
206+
'qid': self.question_json.get('id'),
207+
'question': self.question_json.get('question'),
208+
'ans_1': self.answers[0].get('ans_text'),
209+
'ans_2': self.answers[1].get('ans_text'),
210+
'ans_3': self.answers[2].get('ans_text'),
211+
'ans_4': self.answers[3].get('ans_text'),
212+
'answer': self.answers[answer-1].get('ans_text'),
213+
'source': self.question_json.get('source'),
214+
'author': self.question_json.get('author'),
215+
'category': self.category and len(self.category) == 1 and self.category[0] or None,
216+
}
217+
save_question(question_submit_content)
218+
except Exception as e:
219+
logger.error(f"题库上传失败,此报错不影响正常答题: {str(e)}")
220+
183221
# 创建答题会话实例
184222
quiz_session = QuizSession()
185223

0 commit comments

Comments
 (0)