This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
clock.py
161 lines (160 loc) · 6.43 KB
/
clock.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
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
import requests
from bs4 import BeautifulSoup
import re
import yagmail
import os
# proxies = {
# "http": "http://117.160.132.37:9091"
# }
obj = re.compile('parent.window.location="(?P<url>.*?)"', re.S)
obj1 = re.compile('失败', re.S)
obj2 = re.compile('<div style="width:100%;height:30px;"></div>(?P<success>.*?)onclick="window.location', re.S)
resp = requests.post('https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/first0')
resp.encoding = 'utf8'
# print(resp.text)
# print('---------------------------------------------------------------------------------------')
soup = BeautifulSoup(resp.text, "html.parser")
values = soup.find_all('input')
data = {
'uid': os.environ["uid"], # -------------------------------这里输入学号(必填)!
'upw': os.environ["upw"], # ---------------------------------这里输入密码(必填)!
'smbtn': values[2]['value'],
'hh28': values[3]['value']
}
resp = requests.post("https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/login", data=data)
# print(resp.text)
# print('---------------------------------------------------------------------------------------')
resp.encoding = 'utf8'
url = obj.search(resp.text).group('url')
resp = requests.get(url=url)
resp.encoding = 'utf8'
soup = BeautifulSoup(resp.text, "html.parser")
value = soup.find('iframe')
url = value['src']
resp = requests.get(url)
soup = BeautifulSoup(resp.text, "html.parser")
values = soup.find_all('input')
data = {
'did': values[0]['value'],
'door': values[1]['value'],
'fun18': values[2]['value'],
'sid': values[3]['value'],
'men6': values[4]['value'],
'ptopid': values[5]['value'],
'sid': values[6]['value'],
}
resp = requests.post('https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb', data=data)
resp.encoding = 'utf8'
page = BeautifulSoup(resp.text, "html.parser")
# 如果有验证码
if page.find('img') is not None:
img = page.find('img')['src']
# 这里是对验证码的提取(百度文字识别接口)
data = {
'grant_type': 'client_credentials',
'client_id': 'WNChcFVChONBFqX6xmrkMDMV',
'client_secret': 'ou9XkXXPGQ5tIsqqhYFsrP0ZY0gch9dD'
}
resp = requests.post('https://aip.baidubce.com/oauth/2.0/token', data=data)
access_token = resp.json()['access_token']
data = {
'url': img
}
headers = {
'content-type': 'application/x-www-form-urlencoded'
}
resp = requests.post('https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting?access_token=' + access_token, data=data,
headers=headers)
print(resp.text)
results = resp.json()['words_result'][0]['words']
num_dict = {
'零': 0,
'壹': 1,
'贰': 2,
'叁': 3,
'肆': 4,
'伍': 5,
'陆': 6,
'柒': 7,
'捌': 8,
'玖': 9,
}
res = str(num_dict[results[0]]) + str(num_dict[results[1]]) + str(num_dict[results[2]]) + str(num_dict[results[3]])
data = {
'myvs_94c': res,
'myvs_1': '否',
'myvs_2': '否',
'myvs_3': '否',
'myvs_4': '否',
'myvs_5': '否',
'myvs_7': '否',
'myvs_8': '否',
'myvs_11': '否',
'myvs_12': '否',
'myvs_13': '否',
'myvs_15': '否',
'myvs_13a': '41', # 河南省
'myvs_13b': os.environ["city"], # (郑州市:4101)
'myvs_13c': '文化路97号', # 街道
'myvs_24': '否', # 是否为当日返郑人员
'memo22': '成功获取',
'did': page.find("input", attrs={"name": "did"})['value'],
'door': page.find("input", attrs={"name": "door"})['value'],
'day6': page.find("input", attrs={"name": "day6"})['value'],
'men6': page.find("input", attrs={"name": "men6"})['value'],
'sheng6': page.find("input", attrs={"name": "sheng6"})['value'],
'shi6': page.find("input", attrs={"name": "shi6"})['value'],
'fun3': page.find("input", attrs={"name": "fun3"})['value'],
'jingdu': page.find("input", attrs={"name": "jingdu"})['value'],
'weidu': page.find("input", attrs={"name": "weidu"})['value'],
'ghdn28': page.find("input", attrs={"name": "ghdn28"})['value'],
'ptopid': page.find("input", attrs={"name": "ptopid"})['value'],
'sid': page.find("input", attrs={"name": "sid"})['value']
}
else:
data = {
'myvs_1': '否',
'myvs_2': '否',
'myvs_3': '否',
'myvs_4': '否',
'myvs_5': '否',
'myvs_7': '否',
'myvs_8': '否',
'myvs_11': '否',
'myvs_12': '否',
'myvs_13': '否',
'myvs_15': '否',
'myvs_13a': '41', # 河南省
'myvs_13b': os.environ["city"], # (郑州市:4101)
'myvs_13c': '文化路97号', # 街道
'myvs_24': '否', # 是否为当日返郑人员
'memo22': '成功获取',
'did': page.find("input", attrs={"name": "did"})['value'],
'door': page.find("input", attrs={"name": "door"})['value'],
'day6': page.find("input", attrs={"name": "day6"})['value'],
'men6': page.find("input", attrs={"name": "men6"})['value'],
'sheng6': page.find("input", attrs={"name": "sheng6"})['value'],
'shi6': page.find("input", attrs={"name": "shi6"})['value'],
'fun3': page.find("input", attrs={"name": "fun3"})['value'],
'jingdu': page.find("input", attrs={"name": "jingdu"})['value'],
'weidu': page.find("input", attrs={"name": "weidu"})['value'],
'ghdn28': page.find("input", attrs={"name": "ghdn28"})['value'],
'ptopid': page.find("input", attrs={"name": "ptopid"})['value'],
'sid': page.find("input", attrs={"name": "sid"})['value']
}
resp = requests.post("https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb", data=data)
resp.encoding = 'utf8'
soup = BeautifulSoup(resp.text, "html.parser")
yag = yagmail.SMTP(user='[email protected]', password='xrpalckormpjjijh', host='smtp.qq.com')
if obj1.search(resp.text) is None:
print('打卡成功!')
contents = obj2.search(resp.text).group('success')
yag.send(to=os.environ["email"], subject='zzuClock打卡成功!', contents=contents)
yag.close()
print('发送邮件成功!')
else:
contents = f'<h1>自动打卡失败,请及时打卡!</h1><h1>失败原因:{soup.find("li").text}</h1>'
yag.send(to=os.environ["email"], subject='zzuClock打卡失败!', contents=contents)
yag.close()
print('打卡失败!')
print('失败原因:' + soup.find("li").text)