Skip to content

Commit

Permalink
feat: 经实际测试后进行了一些修改
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ue1nWh1te committed Jan 1, 2022
1 parent 1d23ffb commit 4aac7df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions automaton/devtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ async def _verify(self): # 校验客户端和配置文件中的用户是否相
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)
xhr.withCredentials = true
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)}')
Expand Down
6 changes: 2 additions & 4 deletions automaton/spider/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ async def get_courses(self): # 获取课程列表

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={
Expand All @@ -94,7 +93,6 @@ async def get_books(self, course_id): # 获取某课程的书籍列表
'courseId': course_id
}
)).json()['data']
logger.success('[获取书籍列表] | 获取书籍列表成功')
return books
except Exception:
exceptionInformation = sys.exc_info()
Expand Down Expand Up @@ -163,7 +161,7 @@ async def get_paper(self, paper_id): # 获取任务点信息(包括题目和
'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:
Expand All @@ -173,7 +171,7 @@ async def get_paper(self, paper_id): # 获取任务点信息(包括题目和
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:
Expand Down
2 changes: 1 addition & 1 deletion automaton/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def dfs(node, depth=0):

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(): # 对当前课程或书籍执行刷课
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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='列出所有课程和书籍')
Expand All @@ -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)
Expand Down

0 comments on commit 4aac7df

Please sign in to comment.