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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
import requests
import sys
import datetime
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def send_email(status, email, abbr, now_time):
mail_host = "smtp.qq.com" #现在是qq邮箱
mail_user = "xxxxxxx" #**发送打卡信息的邮箱**
mail_pass = "xxxxxxx" #**邮箱授权码**
sender = 'xxxxxxx' #**邮件发送方的邮箱**
receivers = [] # 接收邮件方
receivers.append(email)
if status: text = '打卡成功!!!'
else : text = '打卡失败 T_T,请手动打卡'
message = MIMEText(text + '今天是' + now_time + '\n如有信息变动,请即时反馈\n如果有一天没收到邮件请手动打卡', 'plain', 'utf-8')
message['From'] = Header("xxxxxxx", 'utf-8') #**邮件发送方的名字(自定义)**
message['To'] = Header(abbr, 'utf-8')
subject = text
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP_SSL()
smtpObj.connect(mail_host, 465) #在阿里云上要用465端口和ssl
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException:
print("Error: 无法发送邮件")
def daka(user_data):
session = requests.Session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36'
}
login_url = 'http://ids.hhu.edu.cn/amserver/UI/Login'
user = user_data['user_name']
password = user_data['password']
data = {
'Login.Token1': user,
'Login.Token2': password,
'goto': 'http://my.hhu.edu.cn/loginSuccess.portal',
'gotoOnFail': 'http://my.hhu.edu.cn/loginFailure.portal'
}
login_response_text = session.post(url=login_url, headers=headers, data=data).text
if 'handleLoginSuccessed' in login_response_text:
print('登录成功')
else:
print('登录失败,请修改用户名和密码重新登录')
sys.exit()
ui_url = 'http://form.hhu.edu.cn/pdc/form/list'
session.get(url=ui_url, headers=headers)
form_url = 'http://form.hhu.edu.cn/pdc/formDesignApi/initFormAppInfo'
data = {
'selfFormWid': 'A335B048C8456F75E0538101600A6A04'
}
form_response = session.post(url=form_url, data=data, headers=headers)
print('获得表单界面状态码', form_response.status_code)
post_url = 'http://form.hhu.edu.cn/pdc/formDesignApi/dataFormSave?wid=A335B048C8456F75E0538101600A6A04&userId=' + user
now_time = datetime.datetime.now().strftime('%Y/%m/%d')
data = {
'DATETIME_CYCLE': now_time,
'XGH_336526': user_data['XGH_336526'],
'XM_1474': user_data['XM_1474'],
'SFZJH_859173': user_data['SFZJH_859173'],
'SELECT_941320': user_data['SELECT_941320'],
'SELECT_459666': user_data['SELECT_459666'],
'SELECT_814855': user_data['SELECT_814855'],
'SELECT_525884': user_data['SELECT_525884'],
'SELECT_125597': user_data['SELECT_125597'],
'TEXT_950231': user_data['TEXT_950231'],
'TEXT_937296': user_data['TEXT_937296'],
'RADIO_853789': '否',
'RADIO_43840': '否',
'RADIO_579935': '健康',
'RADIO_138407': '是',
'RADIO_546905':'',
'RADIO_314799':'',
'RADIO_209256':'',
'RADIO_836972':'',
'RADIO_302717':'',
'RADIO_701131':'',
'RADIO_438985':'',
'RADIO_467360':'',
'PICKER_956186':'',
'TEXT_434598':'',
'TEXT_515297':'',
'TEXT_752063':''
}
post_response = session.post(url=post_url, data=data, headers=headers)
print('提交表单后状态码', post_response.status_code)
final_text = post_response.text
print(final_text)
if 'true' in final_text:
print('今天是: ', now_time)
print('打卡成功!!!')
send_email(True, user_data['email'], user_data['abbr'], now_time)
return True
else:
print('打卡失败')
return False
if __name__ == '__main__':
users = []
user2 = {
'name' : 'xxxxxxx', #**打卡者姓名(为了区分不同打卡者)**
'user_name' : 'xxxxxxx', #**用户名(一般是学号)**
'password' : 'xxxxxxx', #**密码**
'XGH_336526': 'xxxxxxx', #**学号**
'XM_1474': 'xxxxxxx', #**姓名**
'SFZJH_859173': 'xxxxxxx', #**身份证号**
'SELECT_941320': 'xxxxxxx', #**学院(只能是选择列表中的值,比如:计信院)**
'SELECT_459666': 'xxxxxxx', #**年级(只能是选择列表中的值,比如:2019级)**
'SELECT_814855': 'xxxxxxx', #**专业(只能是选择列表中的值,比如:计算机)**
'SELECT_525884': 'xxxxxxx', #**班级(只能是选择列表中的值,比如:计算机19_2)**
'SELECT_125597': 'xxxxxxx', #**宿舍楼(只能是选择列表中的值,比如:江宁校区教学区25舍)**
'TEXT_950231': 'xxxxxxx', #**宿舍号,比如205**
'TEXT_937296': 'xxxxxxx', #**手机号码**
'email' : 'xxxxxxx', #**将打卡信息发送至这个邮箱**
'abbr' : 'xxxxxxx' #**名字缩写(用作邮件接受者的名字)**
}
user1 = {
'name' : 'xxxxxxx', #**打卡者姓名(为了区分不同打卡者)**
'user_name' : 'xxxxxxx', #**用户名(一般是学号)**
'password' : 'xxxxxxx', #**密码**
'XGH_336526': 'xxxxxxx', #**学号**
'XM_1474': 'xxxxxxx', #**姓名**
'SFZJH_859173': 'xxxxxxx', #**身份证号**
'SELECT_941320': 'xxxxxxx', #**学院(只能是选择列表中的值,比如:计信院)**
'SELECT_459666': 'xxxxxxx', #**年级(只能是选择列表中的值,比如:2019级)**
'SELECT_814855': 'xxxxxxx', #**专业(只能是选择列表中的值,比如:计算机)**
'SELECT_525884': 'xxxxxxx', #**班级(只能是选择列表中的值,比如:计算机19_2)**
'SELECT_125597': 'xxxxxxx', #**宿舍楼(只能是选择列表中的值,比如:江宁校区教学区25舍)**
'TEXT_950231': 'xxxxxxx', #**宿舍号,比如205**
'TEXT_937296': 'xxxxxxx', #**手机号码**
'email' : 'xxxxxxx', #**将打卡信息发送至这个邮箱**
'abbr' : 'xxxxxxx' #**名字缩写(用作邮件接受者的名字)**
}
#如果还有用户,则继续添加
users.append(user1)
users.append(user2)
for user in users:
T = 10 #打卡失败的尝试次数
while T > 0:
T -= 1
if daka(user_data=user) :
break
print('-------------尝试重新打卡--------------')
if T == 0:
print('最终打卡失败,请尝试手动打卡')
send_email(False, user['email'], user['abbr'], '')
|