This repository was archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (81 loc) · 3.04 KB
/
main.py
File metadata and controls
97 lines (81 loc) · 3.04 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import requests, re, json, sys, codecs
from bs4 import BeautifulSoup
from aes import encryptAES
from config import *
sys.path.append('.')
requests.packages.urllib3.disable_warnings()
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
cas_url = 'https://cas.swjtu.edu.cn/authserver/login?service=http://xgsys.swjtu.edu.cn/cas/onelogin.aspx?type=SPCP'
result = '西南交大健康填报\n'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.78'
}
def submit():
global result
session = requests.Session()
r = session.get(cas_url, headers=header)
soup = BeautifulSoup(r.text, 'lxml')
salt = soup.find(id='pwdDefaultEncryptSalt').get('value')
lt = soup.find(attrs={"name": "lt"}).get('value')
execution = soup.find(attrs={"name": "execution"}).get('value')
encpwd = encryptAES(pwd, salt)
result += 'Try to Login...\n'
data = {
'username': username,
'password': encpwd,
'lt': lt,
'dllt': 'userNamePasswordLogin',
'execution': execution,
'_eventId': 'submit',
'rmShown': 1
}
r = session.post(cas_url, data=data, headers=header, timeout=10)
if str(username) in r.text and 'SPCPTest3' in r.text:
result += "登陆成功!\n"
else:
result += "登陆失败!\n"
return
jump_url = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', r.text)
for i in jump_url:
if 'SPCPTest3' in i:
r = session.get(i, headers=header, timeout=10)
break
soup = BeautifulSoup(r.text, 'lxml')
status = soup.find(class_='plat-title').span.text
result += f"当前状态: {status}\n"
if status != "开启中":
result += '退出中...\n'
return
r = session.get('http://xgsys.swjtu.edu.cn/SPCPTest3/Web/Report/Index', headers=header, timeout=10)
if '我已阅读承诺书,并保证按承诺书内容执行。' not in r.text:
result += '或许已经填报过了?退出中...\n'
return
r = session.post('http://xgsys.swjtu.edu.cn/SPCPTest3/Web/Report/Index', data=submit_data, headers=header, timeout=10)
if '提交成功!' in r.text:
result += '信息申报完成!\n'
else:
result += '填报失败!请自行填报!\n'
def main():
global result
for _ in range(5):
try:
submit()
break
except BaseException as e:
result += '出错,重试中...\n'
result += str(e) + '\n'
continue
print(result)
# Push
if push_plus_token:
headers = {'Content-Type': 'application/json'}
data = {
'token': push_plus_token,
'title': '西南交大健康填报',
'content': result
}
requests.post(url='http://www.pushplus.plus/send', headers=headers, data=json.dumps(data))
if __name__ == '__main__':
main()
def main_handler(event, context):
main()