Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit 504b72b

Browse files
committed
update: rewrite
1 parent 2d1d261 commit 504b72b

File tree

6 files changed

+132
-72
lines changed

6 files changed

+132
-72
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.vs
22
.vscode
33
.idea
4+
tmp
5+
/config.json
46
# Logs
57
logs
68
*.log

App.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import json
5+
import os
6+
import sys
7+
import time
8+
from json.decoder import JSONDecodeError
9+
from shutil import which
10+
11+
from selenium import webdriver
12+
13+
14+
def get_exec_path():
15+
driver_name = 'chromedriver'
16+
path = which(driver_name)
17+
if path is None:
18+
path = which(driver_name, path='.')
19+
if path is None:
20+
print('No chrome driver...')
21+
sys.exit(1)
22+
return path
23+
24+
25+
def get_driver():
26+
# Chrome options
27+
op = webdriver.ChromeOptions()
28+
# 关掉浏览器左上角的通知提示
29+
op.add_argument("--disable-notifications")
30+
# 关闭'chrome正受到自动测试软件的控制'提示
31+
op.add_argument("disable-infobars")
32+
op.add_argument("--start-maximized")
33+
# No gui
34+
op.add_argument("--headless")
35+
# Run under root user
36+
op.add_argument("--no-sandbox")
37+
op.add_argument("--disable-dev-shm-usage")
38+
op.add_argument("--disable-gpu")
39+
40+
driver = webdriver.Chrome(executable_path=get_exec_path(), options=op)
41+
return driver
42+
43+
44+
def log(single, addition):
45+
info = "[{time_tag} 姓名:{yzxx} 学号: {loginName}] {add}"
46+
print(info.format(time_tag=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
47+
yzxx=single.__getitem__('yzxx'),
48+
loginName=single.__getitem__('loginName'), add=addition)
49+
)
50+
51+
52+
def task(driver, single):
53+
driver.get("https://fxgl.jx.edu.cn/4136010406/public/homeQd?loginName="
54+
+ single.__getitem__('loginName')
55+
+ "&loginType=" + str(single.__getitem__('loginType')))
56+
time.sleep(1)
57+
log(single, '自动签到中...')
58+
js = 'async function(){let t=\'REPLACE\';return t=JSON.parse(t),await async function(t){return await new Promise(n=>{$.ajax({url:"https://fxgl.jx.edu.cn/4136010406/studentQd/saveStu",method:"post",data:t,success:function(t){return n(JSON.stringify(t))}})})}(t)}();'
59+
# js.replace("\"","\\\"")
60+
js = js.replace("REPLACE", json.dumps(single.__getitem__('checkIn')))
61+
print(driver.execute_script('return ' + js))
62+
time.sleep(3)
63+
log(single, '自动填写问卷中...')
64+
js = 'async function(){var t=\'REPLACE\',n="https://fxgl.jx.edu.cn/4136010406/";return 0==(t=JSON.parse(t)).sf?n+="dcwjEditNew/dcwjSubmit2":n+="dcwjEditNew/dcwjTsubmit2",await async function(t,n){return await new Promise(i=>{$.ajax({type:"post",url:t,data:{dcwj:JSON.stringify(n)},success:function(t){return i(JSON.stringify(t))}})})}(n,t)}();'
65+
js = js.replace("REPLACE", json.dumps(single.__getitem__('paper')))
66+
print(driver.execute_script('return ' + js))
67+
68+
69+
def main():
70+
json_filename = "./config.json"
71+
try:
72+
with open(json_filename, 'r', encoding='utf-8') as f:
73+
data = json.load(f)
74+
driver = get_driver()
75+
for single in data:
76+
task(driver, single)
77+
time.sleep(1)
78+
driver.quit()
79+
except FileNotFoundError:
80+
print("File is not found: " + os.path.abspath(json_filename))
81+
print("Creating file...")
82+
with open(json_filename, 'w', encoding='utf-8') as f:
83+
json.dump([{
84+
"loginName": "student id",
85+
"yzxx": "name",
86+
"loginType": 0,
87+
"checkIn": {},
88+
"paper": {}
89+
}], f)
90+
except PermissionError:
91+
print("No permission: " + os.path.abspath(json_filename))
92+
except JSONDecodeError:
93+
print("Error file data...")
94+
95+
96+
if __name__ == '__main__':
97+
main()

AutoCheckIn.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rem AutoCheckIn
22
setlocal EnableDelayedExpansion
33
cd %~dp0
4-
python ./index.py
4+
python ./App.py
55
echo "若想使本页面自动关闭的话,编辑 AutoCheckIn.bat 文件,删除或注释 pause 即可"
66
pause

README.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
# AutoCheckIn
22
> 防疫签到的一些处理方法(Python version)
33
4+
## Run
5+
> `exe` 同级目录下面创建一个 `config.json` 文件
6+
> 可以添加多个用户消息,方便批量打卡ヾ(≧▽≦*)o
7+
8+
```json5
9+
[
10+
{
11+
"loginName": "student id",
12+
"yzxx": "name",
13+
"loginType": 0,
14+
"checkIn":{}, //签到的数据
15+
"paper":{} // 问卷的数据
16+
// 推荐通过下面方式获取数据,增加可信度
17+
},
18+
{
19+
"loginName": "student id",
20+
"yzxx": "name",
21+
"loginType": 0,
22+
"checkIn":{}, //签到的数据
23+
"paper":{} // 问卷的数据
24+
// 推荐通过下面方式获取数据,增加可信度
25+
}
26+
]
27+
```
28+
429
1. 登录网站: [https://fxgl.jx.edu.cn/4136010406/](https://fxgl.jx.edu.cn/4136010406/)
530
2. `F12` 打开 `console`
631
3. 进入每日签到界面
732
4. `console` 输入 `submits` 定位代码打上断点,进行一次提交,卡住时终端输入 `console.log(JSON.stringify(param))`
8-
5. 将输出的数据用来覆盖 `checkIn.js` 里面的 `postVaule` 的值
33+
5. 将输出的数据用来覆盖 `config.json` 里面的 `checkIn` 的值
934
6. 进入问卷调查界面
1035
7. `console` 输入 `submit`
1136
8. 双击查看代码
1237
9.`2683` 行打上断点,然后手动提交,卡住时终端输入 `console.log(JSON.stringify(param))`
13-
10. 将输出的数据用来覆盖 `index.js` 里面的 `postVaule` 的值
14-
11. 修改 `index.py` 里面的 `loginInfo` 参数
15-
12. Copy `chromedriver.exe` to PATH
16-
13. Run: `pip install -r requirements.txt`
17-
14. Run: `python index.py`
18-
15. 提交测试通过以后,可以选择 **添加Windows定时任务**,并且执行后可以选择保留窗口,方便查错。
38+
10. 将输出的数据用来覆盖 `config.json` 里面的 `paper` 的值
39+
11. 前往 [https://npm.taobao.org/mirrors/chromedriver/](https://npm.taobao.org/mirrors/chromedriver/) 下载对应版本的 `chromedriver`
40+
12.`chromedriver` 添加到环境变量 (Linux 可直接通过软件源安装: sudo apt install chromedriver chromium -y)
41+
13. Run: `*.exe`
42+
15. 提交测试通过以后,可以选择 **添加定时任务**,并且执行后可以选择保留窗口,方便查错。
1943

2044

2145
### 一些注意事项
22-
1. 因为本项目使用了 `Windows10` 原生通知,所以可能在一些系统里面不会正常显示通知
2346
2. 目前只支持 `Chrome` ,暂时没有支持其他浏览器的计划

index.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
win10toast==0.9
2-
selenium==3.141.0
1+
selenium==3.141.0

0 commit comments

Comments
 (0)