-
Notifications
You must be signed in to change notification settings - Fork 23
/
Report.py
250 lines (237 loc) · 10.1 KB
/
Report.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
from bs4 import BeautifulSoup
from ustclogin import Login
import time
from newtime import create
start_date = time.strftime("%Y-%m-%d 00:00:00",time.localtime(time.time()+8*3600))
end_date = time.strftime("%Y-%m-%d 23:59:59",time.localtime(time.time()+8*3600))
nowday = time.mktime(time.strptime(end_date, "%Y-%m-%d %H:%M:%S"))
monday = time.mktime(time.strptime("2017-01-01 23:59:59", "%Y-%m-%d %H:%M:%S"))
today = int(nowday - monday) // (24 * 3600) % 7
nowday = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()+8*3600))
class Report(object):
def __init__(self, stuid, password):
self.stuid = stuid
self.password = password
self.login = Login(self.stuid, self.password,
"https://weixine.ustc.edu.cn/2020/caslogin")
def getstate(self):
if self.login.login():
data = self.login.result.text
soup = BeautifulSoup(data, "html.parser")
return soup.find("p", {"style":"margin: 5px -10px 0;"}).contents[1].contents[0]
print("login failed")
return False
def report(self, report_data):
if self.login.login():
data = self.login.result.text
data = data.encode("ascii", "ignore").decode("utf-8", "ignore")
soup = BeautifulSoup(data, "html.parser")
token = soup.find("input", {"name": "_token"})["value"]
data = [("_token", token)] + report_data
url = "https://weixine.ustc.edu.cn/2020/daliy_report"
resp = self.login.session.post(url, data=data)
if "上报成功" in resp.text:
print("daily report successful!")
return True
else:
print("daily report failed")
return False
print("login failed")
return False
def cross_campus(self, cross_campus_data):
if self.login.login():
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020").text
soup = BeautifulSoup(data, "html.parser")
headers = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39"
}
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020/apply/daliy/i?t=3",
headers=headers).text
if "关闭进出校报备" in data:
raise ValueError("change method")
data = data.encode("ascii", "ignore").decode("utf-8", "ignore")
soup = BeautifulSoup(data, "html.parser")
token = soup.find("input", {"name": "_token"})["value"]
post_data = cross_campus_data + [
("_token", token),
("start_date", start_date),
("end_date", end_date),
("t", "3"),
]
post = self.login.session.post(
"https://weixine.ustc.edu.cn/2020/apply/daliy/ipost",
data=post_data)
if "?t=d" in post.url:
print("cross campus successful!")
return True
else:
print("cross campus failed")
print(data)
return False
print("login failed")
return False
def apply_cross_campus(self, cross_campus_data):
if self.login.login():
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020").text
soup = BeautifulSoup(data, "html.parser")
headers = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39"
}
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020/stayinout_apply?t=3",
headers=headers).text
soup = BeautifulSoup(data, "html.parser")
xck = soup.find("input", {"name": "files_xck"})["value"]
xck_time = soup.find("input", {"name": "xck_time"})["value"]
akm = soup.find("input", {"name": "files_akm"})["value"]
akm_time = soup.find("input", {"name": "akm_time"})["value"]
# hs = soup.find("input", {"name": "files_hs"})["value"]
hs2 = soup.find("input", {"name": "files_hs2"})["value"]
hs2_time = soup.find("input", {"name": "hs2_time"})["value"]
token = soup.find("input", {"name": "_token"})["value"]
choose_ds = data.split('<option value="')[1].split('"')[0]
print(nowday[11:13])
if int(nowday[11:13]) >= 12:
sd = time.strftime("%Y-%m-%d 00:00:00",time.localtime(time.time()+32*3600))
ed = time.strftime("%Y-%m-%d 23:59:59",time.localtime(time.time()+32*3600))
start_day = 2
else:
sd = time.strftime("%Y-%m-%d 00:00:00",time.localtime(time.time()+8*3600))
ed = time.strftime("%Y-%m-%d 23:59:59",time.localtime(time.time()+8*3600))
start_day = 1
post_data = cross_campus_data + [
("_token", token),
("start_date", sd),
("end_date", ed),
("choose_ds", choose_ds),
("t", "3"),
("files_xck", xck),
("files_akm", akm),
# ("files_hs", hs),
("files_hs2", hs2),
("xck_time", xck_time),
("akm_time", akm_time),
("hs2_time", hs2_time),
("start_day", start_day),
]
post = self.login.session.post(
"https://weixine.ustc.edu.cn/2020/stayinout_apply",
data=post_data)
if post.url[-3:] == 't=t':
print("cross campus successful!")
return True
else:
print("cross campus failed")
f = open("./log.html", 'w')
f.write(data)
f.close()
return False
print("login failed")
return False
def out_school(self, out_school_data):
if self.login.login():
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020").text
soup = BeautifulSoup(data, "html.parser")
headers = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39"
}
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020/apply/daliy/i?t=2",
headers=headers).text
morehs = ("未检测到昨日核酸检测结果,请自行上传" in data)
soup = BeautifulSoup(data, "html.parser")
token = soup.find("input", {"name": "_token"})["value"]
post_data = out_school_data + [
("_token", token),
("start_date", start_date),
("end_date", end_date),
("t", "2"),
]
if morehs:
gid = data.split("gid")[-1].split("'")[2]
sign = data.split("sign")[-1].split("'")[2]
p = self.login.session.post(
"https://weixine.ustc.edu.cn/2020img/api/upload",
data=[
("_token", token),
("gid", gid),
("sign", sign),
("id", "WU_FILE_0"),
("name", "xcm.jpg"),
],
files={
"file": (
"xcm.jpg",
open("xcm.jpg", "rb"),
"image/jpeg",
{},
)
}
)
print('upload hesuannnn')
post_data.append(("files_hs3", "".join(p.text.split('"id":"')[-1].split('"')[0].split('\\'))))
post = self.login.session.post(
"https://weixine.ustc.edu.cn/2020/apply/daliy/ipost",
data=post_data)
if "?t=d" in post.url:
print("out school successful!")
return True
else:
print("out school failed")
print(post_data)
return False
print("login failed")
return False
def upload_code(self, number):
if self.login.login():
data = self.login.session.get(
"https://weixine.ustc.edu.cn/2020/upload/xcm").text
if '关闭相关功能' in data:
print("bad upload code time")
return False
data = data.encode("ascii", "ignore").decode("utf-8", "ignore")
token = data.split("_token")[-1].split("'")[1]
sign = data.split("sign")[-1].split("'")[2]
gid = data.split("gid")[-1].split("'")[2]
create(number)
def run_update(fnm, t):
data = [
("_token", token),
("gid", gid),
("t", t),
("id", "WU_FILE_0"),
("sign", sign),
]
files = {
"file": (
fnm,
open(fnm, "rb"),
"image/jpeg",
{},
)
}
post = self.login.session.post(
"https://weixine.ustc.edu.cn/2020img/api/upload_for_student",
data=data,
files=files,
)
if "true" not in post.text:
print("update failed")
return False
return True
# if run_update("xcm.jpg", 1) & run_update("akm.jpg", 2):
if run_update("xcm.jpg", 1):
print("update successful")
return True
print("login failed")
return False
if __name__ == '__main__':
print(end_date)
print(today)