add: 添加网课网站
This commit is contained in:
91
main.py
91
main.py
@@ -11,28 +11,29 @@
|
|||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import ddddocr
|
import re
|
||||||
|
import time
|
||||||
|
import warnings
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
import ddddocr
|
||||||
|
|
||||||
|
# 修复 ANTIALIAS 错误 - 添加猴子补丁
|
||||||
|
import PIL.Image
|
||||||
|
import requests
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from lxml import etree # type: ignore
|
from lxml import etree # type: ignore
|
||||||
from threading import Thread
|
|
||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
from urllib3.util.retry import Retry
|
from urllib3.util.retry import Retry
|
||||||
import warnings
|
|
||||||
|
|
||||||
from deepseek import DeepSeek
|
from deepseek import DeepSeek
|
||||||
from doubao import DOUBAO
|
from doubao import DOUBAO
|
||||||
from kimi import KIMI
|
from kimi import KIMI
|
||||||
|
|
||||||
# 修复 ANTIALIAS 错误 - 添加猴子补丁
|
|
||||||
import PIL.Image
|
|
||||||
|
|
||||||
if not hasattr(PIL.Image, "ANTIALIAS"):
|
if not hasattr(PIL.Image, "ANTIALIAS"):
|
||||||
PIL.Image.ANTIALIAS = PIL.Image.Resampling.LANCZOS # type: ignore
|
PIL.Image.ANTIALIAS = PIL.Image.Resampling.LANCZOS # type: ignore
|
||||||
|
|
||||||
@@ -306,13 +307,13 @@ class CKWK:
|
|||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
qa_path = resp.json().get("url", "")
|
qa_path = resp.json().get("url", "")
|
||||||
self.start_url = "https://{}{}".format(self.host, qa_path)
|
self.start_url = "https://{}{}".format(self.host, qa_path)
|
||||||
self.log(f'开始作业: {resp.json().get("msg", "")} url -> {self.start_url}')
|
self.log(f"开始作业: {resp.json().get('msg', '')} url -> {self.start_url}")
|
||||||
resp2 = self.session.get(self.start_url)
|
resp2 = self.session.get(self.start_url)
|
||||||
self.qas = []
|
self.qas = []
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
self.parse_q_a_work(resp2.text)
|
self.parse_q_a_work(resp2.text)
|
||||||
else:
|
else:
|
||||||
self.log(f'开始作业: {resp.json().get("msg", "")}')
|
self.log(f"开始作业: {resp.json().get('msg', '')}")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -327,13 +328,13 @@ class CKWK:
|
|||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
qa_path = resp.json().get("url", "")
|
qa_path = resp.json().get("url", "")
|
||||||
self.start_url = "https://{}{}".format(self.host, qa_path)
|
self.start_url = "https://{}{}".format(self.host, qa_path)
|
||||||
self.log(f'开始考试: {resp.json().get("msg", "")} url -> {self.start_url}')
|
self.log(f"开始考试: {resp.json().get('msg', '')} url -> {self.start_url}")
|
||||||
resp2 = self.session.get(self.start_url)
|
resp2 = self.session.get(self.start_url)
|
||||||
self.qas = []
|
self.qas = []
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
self.parse_q_a_exam(resp2.text)
|
self.parse_q_a_exam(resp2.text)
|
||||||
else:
|
else:
|
||||||
self.log(f'开始考试: {resp.json().get("msg", "")}')
|
self.log(f"开始考试: {resp.json().get('msg', '')}")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -379,7 +380,7 @@ class CKWK:
|
|||||||
|
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(
|
self.log(
|
||||||
f'{index}/{len(self.qas)} 提交答案: {resp.json().get("msg", "")} {answerID} => {answer} {final}'
|
f"{index}/{len(self.qas)} 提交答案: {resp.json().get('msg', '')} {answerID} => {answer} {final}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def exam_submit(
|
def exam_submit(
|
||||||
@@ -410,7 +411,7 @@ class CKWK:
|
|||||||
|
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(
|
self.log(
|
||||||
f'{index}/{len(self.qas)} 提交答案: {resp.json().get("msg", "")} {answerID} => {answer} {final}'
|
f"{index}/{len(self.qas)} 提交答案: {resp.json().get('msg', '')} {answerID} => {answer} {final}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not final:
|
if not final:
|
||||||
@@ -454,7 +455,7 @@ class CKWK:
|
|||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(
|
self.log(
|
||||||
f'添加评论: {resp.json().get("msg", "")} content -> {replace_html_entities(content)}'
|
f"添加评论: {resp.json().get('msg', '')} content -> {replace_html_entities(content)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_reply(self, courseId: str, nodeId: str, replyId: str):
|
def delete_reply(self, courseId: str, nodeId: str, replyId: str):
|
||||||
@@ -466,7 +467,7 @@ class CKWK:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(f'删除评论: {resp.json().get("msg", "")}')
|
self.log(f"删除评论: {resp.json().get('msg', '')}")
|
||||||
|
|
||||||
def reply(self, courseId: str, nodeId: str):
|
def reply(self, courseId: str, nodeId: str):
|
||||||
headers = self.session.headers
|
headers = self.session.headers
|
||||||
@@ -516,7 +517,7 @@ class CKWK:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(f'{resp.json().get("msg", "")} page -> {page}')
|
self.log(f"{resp.json().get('msg', '')} page -> {page}")
|
||||||
self.courses.extend(resp.json().get("list", []))
|
self.courses.extend(resp.json().get("list", []))
|
||||||
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
||||||
self.get_study_record(course_id, page + 1)
|
self.get_study_record(course_id, page + 1)
|
||||||
@@ -532,7 +533,7 @@ class CKWK:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(f'{resp.json().get("msg", "")} page -> {page}')
|
self.log(f"{resp.json().get('msg', '')} page -> {page}")
|
||||||
self.works.extend(resp.json().get("list", []))
|
self.works.extend(resp.json().get("list", []))
|
||||||
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
||||||
self.get_study_record(course_id, page + 1)
|
self.get_study_record(course_id, page + 1)
|
||||||
@@ -547,7 +548,7 @@ class CKWK:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(f'{resp.json().get("msg", "")} page -> {page}')
|
self.log(f"{resp.json().get('msg', '')} page -> {page}")
|
||||||
self.exams.extend(resp.json().get("list", []))
|
self.exams.extend(resp.json().get("list", []))
|
||||||
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
if page < resp.json().get("pageInfo", {}).get("pageCount", 0):
|
||||||
self.get_exam_record(course_id, page + 1)
|
self.get_exam_record(course_id, page + 1)
|
||||||
@@ -555,7 +556,7 @@ class CKWK:
|
|||||||
def log(self, *args, **kwargs) -> None:
|
def log(self, *args, **kwargs) -> None:
|
||||||
exit_flag = False
|
exit_flag = False
|
||||||
time_str = datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
|
time_str = datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
|
||||||
prefix = f'[{self.user.get("name", "")}] {time_str}'
|
prefix = f"[{self.user.get('name', '')}] {time_str}"
|
||||||
# 检查 args 中是否有 \r,若有则将前缀拼在 \r 之后
|
# 检查 args 中是否有 \r,若有则将前缀拼在 \r 之后
|
||||||
if args and isinstance(args[0], str) and "\r" in args[0]:
|
if args and isinstance(args[0], str) and "\r" in args[0]:
|
||||||
# 将前缀插入到最后一个 \r 后面
|
# 将前缀插入到最后一个 \r 后面
|
||||||
@@ -566,7 +567,7 @@ class CKWK:
|
|||||||
else f"{prefix} {args[0]}"
|
else f"{prefix} {args[0]}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
log_content = f'{prefix} {" ".join(map(str, args))}'
|
log_content = f"{prefix} {' '.join(map(str, args))}"
|
||||||
print(log_content, **kwargs)
|
print(log_content, **kwargs)
|
||||||
if exit_flag:
|
if exit_flag:
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
@@ -592,7 +593,7 @@ class CKWK:
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(f'{resp.json().get("msg", "")} --> 1', end="", flush=True)
|
self.log(f"{resp.json().get('msg', '')} --> 1", end="", flush=True)
|
||||||
self.study_id = resp.json().get("studyId", 0)
|
self.study_id = resp.json().get("studyId", 0)
|
||||||
except:
|
except:
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
@@ -616,7 +617,7 @@ class CKWK:
|
|||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(
|
self.log(
|
||||||
f'\r{" " * 100}\r{resp.json().get("msg", "")} --> {study_time}',
|
f"\r{' ' * 100}\r{resp.json().get('msg', '')} --> {study_time}",
|
||||||
end="",
|
end="",
|
||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
@@ -638,7 +639,7 @@ class CKWK:
|
|||||||
)
|
)
|
||||||
if resp.status_code == 200 and resp.json().get("status", False):
|
if resp.status_code == 200 and resp.json().get("status", False):
|
||||||
self.log(
|
self.log(
|
||||||
f'\r{" " * 100}\r{resp.json().get("msg", "")} --> {study_time}',
|
f"\r{' ' * 100}\r{resp.json().get('msg', '')} --> {study_time}",
|
||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
@@ -664,17 +665,17 @@ class CKWK:
|
|||||||
thread.start()
|
thread.start()
|
||||||
cs = self.user.get("courses", [])
|
cs = self.user.get("courses", [])
|
||||||
print(
|
print(
|
||||||
f'姓名: {self.user.get("name", "")}\n\t互评: {self.user.get("huping", 0)}\n\t乐学园: {self.user.get("lexueyuan", 0)}\n\t讨论主题: {self.user.get("taolunzhuti", 0)}\n\t学习时长: {self.user.get("study_time", "")}'
|
f"姓名: {self.user.get('name', '')}\n\t互评: {self.user.get('huping', 0)}\n\t乐学园: {self.user.get('lexueyuan', 0)}\n\t讨论主题: {self.user.get('taolunzhuti', 0)}\n\t学习时长: {self.user.get('study_time', '')}"
|
||||||
)
|
)
|
||||||
if len(cs) > 1:
|
if len(cs) > 1:
|
||||||
for i, _c in enumerate(cs):
|
for i, _c in enumerate(cs):
|
||||||
print(f'{i+1}: {_c.get("name", "")} {_c.get("progress", "")}')
|
print(f"{i + 1}: {_c.get('name', '')} {_c.get('progress', '')}")
|
||||||
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
||||||
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
||||||
cs_list = cs
|
cs_list = cs
|
||||||
for c in cs_list:
|
for c in cs_list:
|
||||||
print(f'课程名: {c.get("name", "")}\n\t进度: {c.get("progress", "")}')
|
print(f"课程名: {c.get('name', '')}\n\t进度: {c.get('progress', '')}")
|
||||||
self.log(f'{c.get("name", "")} --> {c.get("id", "")}')
|
self.log(f"{c.get('name', '')} --> {c.get('id', '')}")
|
||||||
|
|
||||||
self.get_study_record(c.get("id", ""))
|
self.get_study_record(c.get("id", ""))
|
||||||
|
|
||||||
@@ -684,7 +685,7 @@ class CKWK:
|
|||||||
# if isReply:
|
# if isReply:
|
||||||
# self.reply(c.get("id", ""), l.get("id", ""))
|
# self.reply(c.get("id", ""), l.get("id", ""))
|
||||||
self.log(
|
self.log(
|
||||||
f'{l.get("name", "")} --> {l.get("id", "")} --> 已经学习过了'
|
f"{l.get('name', '')} --> {l.get('id', '')} --> 已经学习过了"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -695,7 +696,7 @@ class CKWK:
|
|||||||
total_time = 0
|
total_time = 0
|
||||||
video_time, video_state = self.get_course(node_id)
|
video_time, video_state = self.get_course(node_id)
|
||||||
self.log(
|
self.log(
|
||||||
f'{l.get("name", "")} --> {l.get("id", "")} --> {video_time} --> {video_state}'
|
f"{l.get('name', '')} --> {l.get('id', '')} --> {video_time} --> {video_state}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if video_time <= 0:
|
if video_time <= 0:
|
||||||
@@ -722,11 +723,11 @@ class CKWK:
|
|||||||
thread.start()
|
thread.start()
|
||||||
cs = self.user.get("courses", [])
|
cs = self.user.get("courses", [])
|
||||||
print(
|
print(
|
||||||
f'姓名: {self.user.get("name", "")}\n\t互评: {self.user.get("huping", 0)}\n\t乐学园: {self.user.get("lexueyuan", 0)}\n\t讨论主题: {self.user.get("taolunzhuti", 0)}\n\t学习时长: {self.user.get("study_time", "")}'
|
f"姓名: {self.user.get('name', '')}\n\t互评: {self.user.get('huping', 0)}\n\t乐学园: {self.user.get('lexueyuan', 0)}\n\t讨论主题: {self.user.get('taolunzhuti', 0)}\n\t学习时长: {self.user.get('study_time', '')}"
|
||||||
)
|
)
|
||||||
if len(cs) > 1:
|
if len(cs) > 1:
|
||||||
for i, _c in enumerate(cs):
|
for i, _c in enumerate(cs):
|
||||||
print(f'{i+1}: {_c.get("name", "")} {_c.get("progress", "")}')
|
print(f"{i + 1}: {_c.get('name', '')} {_c.get('progress', '')}")
|
||||||
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
||||||
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
||||||
cs_list = cs
|
cs_list = cs
|
||||||
@@ -737,7 +738,7 @@ class CKWK:
|
|||||||
self.qas = []
|
self.qas = []
|
||||||
if "已阅" in work.get("state"):
|
if "已阅" in work.get("state"):
|
||||||
self.log(
|
self.log(
|
||||||
f'{work.get("title", "")} 已阅 {work.get("finalScore", "")}'
|
f"{work.get('title', '')} 已阅 {work.get('finalScore', '')}"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
if not self.get_question_answer_work(
|
if not self.get_question_answer_work(
|
||||||
@@ -766,11 +767,11 @@ class CKWK:
|
|||||||
thread.start()
|
thread.start()
|
||||||
cs = self.user.get("courses", [])
|
cs = self.user.get("courses", [])
|
||||||
print(
|
print(
|
||||||
f'姓名: {self.user.get("name", "")}\n\t互评: {self.user.get("huping", 0)}\n\t乐学园: {self.user.get("lexueyuan", 0)}\n\t讨论主题: {self.user.get("taolunzhuti", 0)}\n\t学习时长: {self.user.get("study_time", "")}'
|
f"姓名: {self.user.get('name', '')}\n\t互评: {self.user.get('huping', 0)}\n\t乐学园: {self.user.get('lexueyuan', 0)}\n\t讨论主题: {self.user.get('taolunzhuti', 0)}\n\t学习时长: {self.user.get('study_time', '')}"
|
||||||
)
|
)
|
||||||
if len(cs) > 1:
|
if len(cs) > 1:
|
||||||
for i, _c in enumerate(cs):
|
for i, _c in enumerate(cs):
|
||||||
print(f'{i+1}: {_c.get("name", "")} {_c.get("progress", "")}')
|
print(f"{i + 1}: {_c.get('name', '')} {_c.get('progress', '')}")
|
||||||
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
cs_order = input("请输入刷课顺序(用英文逗号分隔,不需要耍的不用加): ")
|
||||||
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
cs_list = [cs[int(_c) - 1] for _c in cs_order.split(",")]
|
||||||
cs_list = cs
|
cs_list = cs
|
||||||
@@ -781,7 +782,7 @@ class CKWK:
|
|||||||
self.qas = []
|
self.qas = []
|
||||||
if "线下阅" in exam.get("state"):
|
if "线下阅" in exam.get("state"):
|
||||||
self.log(
|
self.log(
|
||||||
f'{exam.get("title", "")} 已阅 {exam.get("finalScore", "")}'
|
f"{exam.get('title', '')} 已阅 {exam.get('finalScore', '')}"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
print(exam)
|
print(exam)
|
||||||
@@ -807,9 +808,13 @@ class CKWK:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
host_server = [
|
host_server = [
|
||||||
["cqcst.yuruixxkj.com", "御瑞科技(选修课)"],
|
# ["cqcst.yuruixxkj.com", "御瑞科技(选修课)"],
|
||||||
["cqcst.zjxkeji.com", "重庆城市科技学院(其他1)"],
|
# ["cqcst.zjxkeji.com", "重庆城市科技学院(其他1)"],
|
||||||
["cqcst.yuncanjykeji.com", "重庆城市科技学院实训平台(其他2)"],
|
# ["cqcst.yuncanjykeji.com", "重庆城市科技学院实训平台(其他2)"],
|
||||||
|
["cqcst.leykeji.com", "劳动课程测评考试平台"],
|
||||||
|
# ["cqcst.zjxkeji.com", "公益课程平台"],
|
||||||
|
["cqcst.suwankj.com", "在线课程测评考试平台"],
|
||||||
|
# ["cqcst.yuruixxkj.com", "在线测评考试平台"],
|
||||||
]
|
]
|
||||||
for i, h in enumerate(host_server):
|
for i, h in enumerate(host_server):
|
||||||
print(f"{i + 1}: {h[0]} {h[1]}")
|
print(f"{i + 1}: {h[0]} {h[1]}")
|
||||||
@@ -835,7 +840,7 @@ if __name__ == "__main__":
|
|||||||
# CKWK(f"{u}", f"{p}", host_server[c][0]).run()
|
# CKWK(f"{u}", f"{p}", host_server[c][0]).run()
|
||||||
|
|
||||||
# 刷作业,不需要用的时候可以直接注释
|
# 刷作业,不需要用的时候可以直接注释
|
||||||
# CKWK(f"{u}", f"{p}", host_server[c][0]).work()
|
CKWK(f"{u}", f"{p}", host_server[c][0]).work()
|
||||||
|
|
||||||
# 考试,不需要用的时候可以直接注释
|
# 考试,不需要用的时候可以直接注释
|
||||||
CKWK(f"{u}", f"{p}", host_server[c][0]).exam()
|
# CKWK(f"{u}", f"{p}", host_server[c][0]).exam()
|
||||||
|
|||||||
Reference in New Issue
Block a user