feat: 经实际测试后进行了一些修改

master
B1ue1nWh1te 3 years ago
parent 1d23ffb27f
commit 4aac7dfe03

@ -24,7 +24,7 @@ class Browser(object):
try: try:
logger.info('[账号校验] | 正在校验账号...') logger.info('[账号校验] | 正在校验账号...')
page = await self.wait_for_page(r'https?://.*') page = await self.wait_for_page(r'https?://.*')
user_info = (await page.eval(''' user_info = json.loads((await page.eval('''
(function () { (function () {
var xhr = new XMLHttpRequest() var xhr = new XMLHttpRequest()
xhr.open('POST', 'https://school.ismartlearning.cn/client/user/student-info', false) xhr.open('POST', 'https://school.ismartlearning.cn/client/user/student-info', false)
@ -32,7 +32,7 @@ class Browser(object):
xhr.send(null) xhr.send(null)
return xhr.responseText return xhr.responseText
})() })()
'''))['result']['value']['data'] '''))['result']['value'])['data']
spider_user = configs['user']['username'] spider_user = configs['user']['username']
logger.debug(f'[账号校验] | 配置文件用户: {spider_user}') logger.debug(f'[账号校验] | 配置文件用户: {spider_user}')
logger.debug(f'[账号校验] | 客户端用户: {json.dumps(user_info, indent=4)}') logger.debug(f'[账号校验] | 客户端用户: {json.dumps(user_info, indent=4)}')

@ -80,7 +80,6 @@ class Spider(httpx.AsyncClient):
async def get_books(self, course_id): # 获取某课程的书籍列表 async def get_books(self, course_id): # 获取某课程的书籍列表
try: try:
logger.info('[获取书籍列表] | 正在获取书籍列表...')
await self.post( # 必须有这个请求,否则后面会报错 await self.post( # 必须有这个请求,否则后面会报错
'http://school.ismartlearning.cn/client/course/list-of-student?status=1', 'http://school.ismartlearning.cn/client/course/list-of-student?status=1',
data={ data={
@ -94,7 +93,6 @@ class Spider(httpx.AsyncClient):
'courseId': course_id 'courseId': course_id
} }
)).json()['data'] )).json()['data']
logger.success('[获取书籍列表] | 获取书籍列表成功')
return books return books
except Exception: except Exception:
exceptionInformation = sys.exc_info() exceptionInformation = sys.exc_info()
@ -163,7 +161,7 @@ class Spider(httpx.AsyncClient):
'Accept-Encoding': 'gzip, deflate' 'Accept-Encoding': 'gzip, deflate'
} }
)).json()['data'] )).json()['data']
logger.debug(f'[获取任务点] | {json.dumps(paper_info, indent=4)}') # logger.debug(f'[获取任务点] | {json.dumps(paper_info, indent=4)}')
logger.success('[获取任务点] | 获取任务点信息完成') logger.success('[获取任务点] | 获取任务点信息完成')
return paper_info return paper_info
except Exception: except Exception:
@ -173,7 +171,7 @@ class Spider(httpx.AsyncClient):
async def user_info(self): async def user_info(self):
try: try:
logger.info('[获取用户信息] | 正在获取用户信息...') logger.info('[获取用户信息] | 正在获取用户信息...')
info = await self.post('https://school.ismartlearning.cn/client/user/student-info').json() info = (await self.post('https://school.ismartlearning.cn/client/user/student-info')).json()
logger.success('[获取用户信息] | 获取用户信息完成') logger.success('[获取用户信息] | 获取用户信息完成')
return info return info
except Exception: except Exception:

@ -105,7 +105,7 @@ async def _flash(course_id, book_id, spider):
async def flash_by_id(identity): async def flash_by_id(identity):
async with Spider() as spider: async with Spider() as spider:
await _flash(*identity.split('#'), spider) await _flash(*identity.split('-'), spider)
async def flash_current(): # 对当前课程或书籍执行刷课 async def flash_current(): # 对当前课程或书籍执行刷课

@ -8,7 +8,7 @@ from argparse import ArgumentParser
async def main(): async def main():
parser = ArgumentParser('main.py') parser = ArgumentParser('main.py')
parser.add_argument('-v', dest='level', action='count', help='日志过滤等级,依次为 warning, info, debug, success') # parser.add_argument('-v', dest='level', action='count', help='日志过滤等级,依次为 warning, info, debug, success')
subparsers = parser.add_subparsers(dest='method', help='模式选择') subparsers = parser.add_subparsers(dest='method', help='模式选择')
method_list = subparsers.add_parser('list', help='列出所有课程和书籍') method_list = subparsers.add_parser('list', help='列出所有课程和书籍')
@ -18,13 +18,13 @@ async def main():
target = method_flash.add_mutually_exclusive_group() target = method_flash.add_mutually_exclusive_group()
target.add_argument('-i', '--id', help='指定书籍ID') target.add_argument('-i', '--id', help='指定书籍ID')
target.add_argument('-c', '--current', action='store_true', help='限定为当前课程或书籍') target.add_argument('-c', '--current', action='store_true', help='限定为当前课程或书籍')
target.add_argument('-a', '--all', action='store_true', help='选择全部(慎用 除非你知道自己在进行什么操作)') target.add_argument('-a', '--all', action='store_true', help='刷全部课程(慎用 除非你知道自己在进行什么操作)')
# method_flash.add_argument('-f', '--filter', help='任务过滤器,设置后只刷匹配的任务(尚未实现)') # Todo: 实现这个 # method_flash.add_argument('-f', '--filter', help='任务过滤器,设置后只刷匹配的任务(尚未实现)') # Todo: 实现这个
args = parser.parse_args() args = parser.parse_args()
logger.remove() # logger.remove()
logger.add(sys.stdout, level=['WARNING', 'INFO', 'DEBUG', 'SUCCESS'][args.level or 0]) # logger.add(sys.stdout, level=['WARNING', 'INFO', 'DEBUG'][args.level or 0])
if args.method == 'list': if args.method == 'list':
await utils.list_books(detail=args.detail) await utils.list_books(detail=args.detail)

Loading…
Cancel
Save