|
|
@ -1,8 +1,10 @@
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import httpx
|
|
|
|
import traceback
|
|
|
|
from hashlib import md5
|
|
|
|
from hashlib import md5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
from loguru import logger
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
|
|
|
|
from .captcha import recognize
|
|
|
|
from .captcha import recognize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,8 +21,7 @@ class Tree: # 任务树
|
|
|
|
for ch in self.child:
|
|
|
|
for ch in self.child:
|
|
|
|
ch.sort()
|
|
|
|
ch.sort()
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[构建任务树] | 排序出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[构建任务树] | 排序出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Spider(httpx.AsyncClient):
|
|
|
|
class Spider(httpx.AsyncClient):
|
|
|
@ -58,8 +59,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[登录] | 登录成功')
|
|
|
|
logger.success('[登录] | 登录成功')
|
|
|
|
return info
|
|
|
|
return info
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[登录] | 登录出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[登录] | 登录出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_courses(self): # 获取课程列表
|
|
|
|
async def get_courses(self): # 获取课程列表
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -75,8 +75,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[获取课程列表] | 获取课程列表成功')
|
|
|
|
logger.success('[获取课程列表] | 获取课程列表成功')
|
|
|
|
return courses
|
|
|
|
return courses
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取课程列表] | 获取课程列表出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取课程列表] | 获取课程列表出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_books(self, course_id): # 获取某课程的书籍列表
|
|
|
|
async def get_books(self, course_id): # 获取某课程的书籍列表
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -95,8 +94,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
)).json()['data']
|
|
|
|
)).json()['data']
|
|
|
|
return books
|
|
|
|
return books
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取书籍列表] | 获取书籍列表出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取书籍列表] | 获取书籍列表出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_tasks(self, book_id, book_type, course_id): # 获取某书籍的任务树
|
|
|
|
async def get_tasks(self, book_id, book_type, course_id): # 获取某书籍的任务树
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -133,8 +131,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[获取任务列表] | 获取任务列表完成')
|
|
|
|
logger.success('[获取任务列表] | 获取任务列表完成')
|
|
|
|
return root
|
|
|
|
return root
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取任务列表] | 获取任务列表出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取任务列表] | 获取任务列表出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_paper(self, paper_id): # 获取任务点信息(包括题目和答案)
|
|
|
|
async def get_paper(self, paper_id): # 获取任务点信息(包括题目和答案)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -165,8 +162,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[获取任务点] | 获取任务点信息完成')
|
|
|
|
logger.success('[获取任务点] | 获取任务点信息完成')
|
|
|
|
return paper_info
|
|
|
|
return paper_info
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取任务点] | 获取任务点出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取任务点] | 获取任务点出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def user_info(self):
|
|
|
|
async def user_info(self):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -175,8 +171,7 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[获取用户信息] | 获取用户信息完成')
|
|
|
|
logger.success('[获取用户信息] | 获取用户信息完成')
|
|
|
|
return info
|
|
|
|
return info
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取用户信息] | 获取用户信息出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取用户信息] | 获取用户信息出错:{exceptionInformation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def book_info(self, book_id):
|
|
|
|
async def book_info(self, book_id):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -208,5 +203,4 @@ class Spider(httpx.AsyncClient):
|
|
|
|
logger.success('[获取书籍信息] | 获取书籍信息完成')
|
|
|
|
logger.success('[获取书籍信息] | 获取书籍信息完成')
|
|
|
|
return book_info
|
|
|
|
return book_info
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
exceptionInformation = sys.exc_info()
|
|
|
|
logger.warning(f'[获取书籍信息] | 获取书籍信息出错:\n{traceback.format_exc()}')
|
|
|
|
logger.warning(f'[获取书籍信息] | 获取书籍信息出错:{exceptionInformation}')
|
|
|
|
|
|
|
|