Skip to content

Commit

Permalink
Merge pull request Mufanc#14 from B1ue1nWh1te/master
Browse files Browse the repository at this point in the history
对原版进行了一些优化
  • Loading branch information
Mufanc authored Jan 1, 2022
2 parents 0a569f8 + b1a3163 commit 28e5c8b
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 474 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.cache/*
/venv/
/.idea/
/.vscode/
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/iSmartAuto2.iml

This file was deleted.

105 changes: 0 additions & 105 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
## iSmart 课程自动姬 v1.0.2
## iSmart 课程自动姬

### 效果展示

* 拥有更好的题型适应性,理论上适配所有客观题种类

* 提升稳定性,中途宕机概率大大降低
- 拥有更好的题型适应性,理论上适配所有客观题种类
- 提升稳定性,中途宕机概率大大降低

* 采用全新思路,相较 [自动化方案](https://github.com/Mufanc/iSmartAuto) ,效率提升超过 1000%
- 采用全新思路,相较 [自动化方案](https://github.com/Mufanc/iSmartAuto) ,效率提升超过 1000%

![](images/demo.png)


### 工作原理

Expand All @@ -23,13 +21,13 @@

#### Q&A

* **Q:** 既然是回传分数,那为何不用 Python 直接将分数上报,反而要走 cdp?
- **Q:** 既然是回传分数,那为何不用 Python 直接将分数上报,反而要走 cdp?

>   上报分数的请求中有疑似 Hash 的字段 `ut`,且生成 `ut` 的方法 native,无法通过分析 JavaScript 得到(有木有大佬会 ollydbg 的来交个 PR)
<br/>

* **Q:** 使用这个脚本,会不会被检测到作弊?
- **Q:** 使用这个脚本,会不会被检测到作弊?

> &emsp;&emsp;不排除这样的可能性,相较自动化而言,目前的方式提交的数据尚不完整(但成绩和学习时长会被记录),若是仔细比对,有可能会发现数据异常
Expand All @@ -54,7 +52,7 @@ cd iSmartAuto2
pip install -r requirements.txt
```

&emsp;&emsp;感谢 [@cyp0633](https://github.com/cyp0633)[提醒](https://github.com/Mufanc/iSmartAuto2/pull/8),现已将 `requirements.txt` 中的 websockets 版本降级为 8.1
/_&emsp;&emsp;感谢 [@cyp0633](https://github.com/cyp0633)[提醒](https://github.com/Mufanc/iSmartAuto2/pull/8),现已将 `requirements.txt` 中的 websockets 版本降级为 8.1_/

#### 配置 iSmart 客户端

Expand All @@ -66,23 +64,23 @@ pip install -r requirements.txt

&emsp;&emsp;修改 `configs.yml` 中的账号和密码,保证与 iSmart 客户端中登录的账号一致,然后根据需要调整下方参数。在终端中执行 `py main.py -h` 可以查看更多帮助信息,这里列举几个常用命令

* 列出所有课程和书籍的详细信息
- 列出所有课程和书籍的详细信息

```shell
py main.py list -d
```

<br/>

* 根据书籍 id 执行刷课
- 根据书籍 id 执行刷课

```shell
py main.py flash -i 51627#7B6911511DB6B33638F6C58531D8FBD3
py main.py flash -i 51627-7B6911511DB6B33638F6C58531D8FBD3
```

<br/>

* 根据当前打开的页面执行刷课
- 根据当前打开的页面执行刷课

```shell
py main.py flash -c
Expand All @@ -96,24 +94,20 @@ py main.py flash -c

![](images/current_course.png)

### 过滤器语法

* 待完善

### 常见问题

* 无法刷课?
- 无法刷课?

&emsp;&emsp;**除非明确要求用户输入,本项目中的所有 Warning 都不会阻塞**,如果你莫名其妙卡住了,控制台又没有要求你输入,那么大概率是 未适配你的课程/环境没配置好/网络问题

* 父节点不存在?
- 父节点不存在?

&emsp;&emsp;不会因为报这个 Warning 而卡住,如果脚本运行完之后你发现所有任务点确实都刷到了,那么完全不用管这个 Warning

* 账号密码与登录不符?
- 账号密码与登录不符?

&emsp;&emsp;脚本判断的逻辑比较粗糙,弹警告只是提醒你务必确保 iSmart 客户端和 `configs.yml` 中是同一个账号,确定无误后大胆使用即可

* **提 issue 前请看这个 ↓↓↓**
- **提 issue 前请看这个 ↓↓↓**

&emsp;&emsp;如果脚本出现异常,请检查你的课程和我学的是不是同一门(见上图),不同课程的参数可能会有细微差异,导致获取不到任务或者别的一些诡异现象。如果你有一定的爬虫开发经验,相信你自己可以通过该修改源代码很快解决这些问题;如果你只是想刷课,那么非常抱歉我并没有时间和经历去对每一本教材都做适配
&emsp;&emsp;如果脚本出现异常,请检查你的课程和我学的是不是同一门(见上图),不同课程的参数可能会有细微差异,导致获取不到任务或者别的一些诡异现象。如果你有一定的爬虫开发经验,相信你自己可以通过该修改源代码很快解决这些问题;如果你只是想刷课,那么非常抱歉我并没有时间和精力去对每一本教材都做适配
58 changes: 30 additions & 28 deletions automaton/devtools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import asyncio
import json
import re
import urllib.parse as parser

import sys
import json
import httpx
import asyncio
import websockets
import urllib.parse as parser
from loguru import logger

from configs import configs


Expand All @@ -22,33 +21,36 @@ def __init__(self, dev_port):
self.port = dev_port

async def _verify(self): # 校验客户端和配置文件中的用户是否相同
logger.info('正在校验账号...')
page = await self.wait_for_page(r'https?://.*')
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']
spider_user = configs['user']['username']
logger.debug(f'spider: {spider_user}')
logger.debug(f'iSmart client: {json.dumps(user_info, indent=4)}')
if str(spider_user) != user_info['mobile'] and str(spider_user) != user_info['username']:
logger.warning('检测到 iSmart 客户端中登录的账号与配置文件中账号不符!')
choice = input('继续使用可能会出现意料之外的问题,是否继续?[y/N]')
if choice.lower() != 'y':
exit()
else:
logger.info('校验通过!')
return True
try:
logger.info('[账号校验] | 正在校验账号...')
page = await self.wait_for_page(r'https?://.*')
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']
spider_user = configs['user']['username']
logger.debug(f'[账号校验] | 配置文件用户: {spider_user}')
logger.debug(f'[账号校验] | 客户端用户: {json.dumps(user_info, indent=4)}')
if str(spider_user) != user_info['mobile'] and str(spider_user) != user_info['username']:
logger.warning('[账号校验] | 客户端中登录的账号与配置文件中账号不符')
choice = input('[账号校验] | 继续使用可能会出现意料之外的问题,是否继续?[y/N]')
if choice.lower() != 'y':
exit()
else:
logger.info('[账号校验] | 校验通过')
return True
except Exception:
exceptionInformation = sys.exc_info()
logger.warning(f'[账号校验] | 账号校验出错:{exceptionInformation}')

async def wait_for_page(self, regexp): # 等待符合条件的页面出现
async with httpx.AsyncClient() as client:
while True:
logger.info('等待可用页面...')
try:
pages = (await client.get(f'http://127.0.0.1:{self.port}/json')).json()
for page in pages:
Expand Down
Loading

0 comments on commit 28e5c8b

Please sign in to comment.