-
Notifications
You must be signed in to change notification settings - Fork 6
/
iamok.py
67 lines (52 loc) · 1.79 KB
/
iamok.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#_*_coding: utf-8 _*_
import time
import requests
import json
import re
import os
import execjs
# import http.cookiejar as cj
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
def submit():
#账户信息
user = os.environ["SCUT_USERNAME"]
passwd = os.environ["SCUT_PASSWORD"]
session = requests.Session()
#登陆页面
url_1 = 'https://sso.scut.edu.cn/cas/login?service=https%3A%2F%2Fiamok.scut.edu.cn%2Fcas%2Flogin'
#利用des.js文件加密,得到登陆表单数据rsa
r = session.get(url_1)
lt = re.findall('name="lt" value="(.*?)"', r.text)[0]
execution = re.findall('name="execution" value="(.*?)"', r.text)[0]
with open('des.js') as f:
ctx = execjs.compile(f.read())
string1 = user + passwd + lt
rsa = ctx.call('strEnc', string1, '1', '2', '3')
#登陆所需的表单数据
login_data = {
'rsa': rsa,
'ul': len(user),
'pl': len(passwd),
'lt': lt,
'execution': execution,
'_eventId': 'submit'
}
##进行登陆登陆
session.post(url_1, data=login_data)
#optional,保存cookie到本地
# session.cookies.save('cookie.txt', ignore_discard=True, ignore_expires=True)
#get请求链接,解析你的健康数据
url_2 = 'https://iamok.scut.edu.cn/mobile/recordPerDay/getRecordPerDay'
html = session.get(url_2)
submit_data = html.json()['data']
#post请求链接,提交新的健康数据
url_3 = 'https://iamok.scut.edu.cn/mobile/recordPerDay/submitRecordPerDay'
output = session.post(url_3, json=submit_data)
print(output.text)
return output
code = 500
if __name__ == "__main__":
while code != 200:
output = submit()
code = json.loads(output.text)["code"]
print("您已成功提交健康信息!")