From 4aac7dfe03b4472294eb5dce7359144b1fc57907 Mon Sep 17 00:00:00 2001 From: B1ue1nWh1te <708968728@qq.com> Date: Sat, 1 Jan 2022 14:37:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=8F=E5=AE=9E=E9=99=85=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=90=8E=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- automaton/devtools.py | 4 ++-- automaton/spider/spider.py | 6 ++---- automaton/utils.py | 2 +- main.py | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/automaton/devtools.py b/automaton/devtools.py index bbf2247..19f2482 100644 --- a/automaton/devtools.py +++ b/automaton/devtools.py @@ -24,7 +24,7 @@ class Browser(object): try: logger.info('[账号校验] | 正在校验账号...') page = await self.wait_for_page(r'https?://.*') - user_info = (await page.eval(''' + user_info = json.loads((await page.eval(''' (function () { var xhr = new XMLHttpRequest() xhr.open('POST', 'https://school.ismartlearning.cn/client/user/student-info', false) @@ -32,7 +32,7 @@ class Browser(object): xhr.send(null) return xhr.responseText })() - '''))['result']['value']['data'] + '''))['result']['value'])['data'] spider_user = configs['user']['username'] logger.debug(f'[账号校验] | 配置文件用户: {spider_user}') logger.debug(f'[账号校验] | 客户端用户: {json.dumps(user_info, indent=4)}') diff --git a/automaton/spider/spider.py b/automaton/spider/spider.py index 7efebb7..96ecbe8 100644 --- a/automaton/spider/spider.py +++ b/automaton/spider/spider.py @@ -80,7 +80,6 @@ class Spider(httpx.AsyncClient): async def get_books(self, course_id): # 获取某课程的书籍列表 try: - logger.info('[获取书籍列表] | 正在获取书籍列表...') await self.post( # 必须有这个请求,否则后面会报错 'http://school.ismartlearning.cn/client/course/list-of-student?status=1', data={ @@ -94,7 +93,6 @@ class Spider(httpx.AsyncClient): 'courseId': course_id } )).json()['data'] - logger.success('[获取书籍列表] | 获取书籍列表成功') return books except Exception: exceptionInformation = sys.exc_info() @@ -163,7 +161,7 @@ class Spider(httpx.AsyncClient): 'Accept-Encoding': 'gzip, deflate' } )).json()['data'] - logger.debug(f'[获取任务点] | {json.dumps(paper_info, indent=4)}') + # logger.debug(f'[获取任务点] | {json.dumps(paper_info, indent=4)}') logger.success('[获取任务点] | 获取任务点信息完成') return paper_info except Exception: @@ -173,7 +171,7 @@ class Spider(httpx.AsyncClient): async def user_info(self): try: 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('[获取用户信息] | 获取用户信息完成') return info except Exception: diff --git a/automaton/utils.py b/automaton/utils.py index 2ca9468..20e2f4a 100644 --- a/automaton/utils.py +++ b/automaton/utils.py @@ -105,7 +105,7 @@ async def _flash(course_id, book_id, spider): async def flash_by_id(identity): async with Spider() as spider: - await _flash(*identity.split('#'), spider) + await _flash(*identity.split('-'), spider) async def flash_current(): # 对当前课程或书籍执行刷课 diff --git a/main.py b/main.py index 51e6ebf..5acb856 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ from argparse import ArgumentParser async def main(): 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='模式选择') method_list = subparsers.add_parser('list', help='列出所有课程和书籍') @@ -18,13 +18,13 @@ async def main(): target = method_flash.add_mutually_exclusive_group() target.add_argument('-i', '--id', help='指定书籍ID') 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: 实现这个 args = parser.parse_args() - logger.remove() - logger.add(sys.stdout, level=['WARNING', 'INFO', 'DEBUG', 'SUCCESS'][args.level or 0]) + # logger.remove() + # logger.add(sys.stdout, level=['WARNING', 'INFO', 'DEBUG'][args.level or 0]) if args.method == 'list': await utils.list_books(detail=args.detail)