-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaka_unloop_public.py
209 lines (159 loc) · 6.61 KB
/
daka_unloop_public.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
# coding=utf-8
# from datetime import timezone, datetime, timedelta
import random, traceback, sys, datetime
from pytz import timezone
import smtplib
from email.mime.text import MIMEText
# import csv
import requests, json, time, re
from bs4 import BeautifulSoup
def datetime_as_timezone(date_time, time_zone):
tz = timezone(time_zone)
utc = timezone('UTC')
return date_time.replace(tzinfo=utc).astimezone(tz)
def get_time(need_hour=False):
date_time = datetime.datetime.utcnow()
tz = timezone('Asia/Taipei') # US/Eastern
utc = timezone('UTC')
date_time_tzone = date_time.replace(tzinfo=utc).astimezone(tz)
if need_hour:
return '{0:%Y-%m-%d %H:%M}'.format(date_time_tzone), date_time_tzone.hour
else:
return '{0:%Y-%m-%d %H:%M}'.format(date_time_tzone)
requests.packages.urllib3.disable_warnings()
# not_test = False # 测试=False 正式=True
not_test = True # 测试=False 正式=True
def send_message(addr, context):
if addr == "":
return
if not not_test:
return
print(get_time(), "发送邮件", context, flush=True)
smtp_server = 'smtp.163.com' # smt.qq.com
msg_mail = MIMEText(context + "\n" + get_time() + "\n\n\n Sent by Onya")
msg_mail['Subject'] = context
msg_mail['From'] = fromMail
msg_mail['To'] = "%s;%s" % (fromMail, addr) # 接收消息的邮箱
# msg_mail['To'] = fromMail + ";" + msg["toMail"] # 接收消息的邮箱
try:
s = smtplib.SMTP()
s.connect(smtp_server)
s = smtplib.SMTP_SSL('smtp.163.com', 465)
s.login(fromMail, mailPass)
# s.sendmail(fromMail, msg["toMail"], msg_mail.as_string())
s.sendmail(fromMail, [fromMail, addr], msg_mail.as_string())
s.quit()
except Exception as e:
print('发送失败', str(e), end=' ', flush=True)
requests.packages.urllib3.disable_warnings()
login_url = 'https://ehall.jlu.edu.cn/sso/login'
form_url = 'https://ehall.jlu.edu.cn/infoplus/form/YJSMRDK/start'
start_url = 'https://ehall.jlu.edu.cn/infoplus/interface/start'
render_url = 'https://ehall.jlu.edu.cn/infoplus/interface/render'
action_url = 'https://ehall.jlu.edu.cn/infoplus/interface/doAction'
logout_url = "https://ehall.jlu.edu.cn/taskcenter/logout"
UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 Edg/87.0.664.47'
def get_formurl_by_grade(grade):
url = 'https://ehall.jlu.edu.cn/infoplus/form/' + grade.upper() + 'MRDK/start'
return url
def check(username, password, grade):
while True:
try:
s = requests.Session()
s.verify = False
headers = {'User-Agent': UA}
# login_html = s.get(url=logout_url)
login_html = s.get(url=login_url, headers=headers)
soup = BeautifulSoup(login_html.text, 'lxml')
pid = soup.find(name="input", attrs={"name": "pid"}).get('value')
# login
data = {'username': username, 'password': password, 'pid': pid, 'source': ''}
s.post(url=login_url, data=data, headers=headers)
# get csrf_token
form_html = s.get(url=get_formurl_by_grade(grade), headers=headers)
soup = BeautifulSoup(form_html.text, 'lxml')
csrf_token = soup.find(name="meta", attrs={"itemscope": "csrfToken"}).get('content')
# get addr
headers = {'User-Agent': UA, 'Referer': get_formurl_by_grade(grade)}
data = {'idc': grade.upper() + 'MRDK', 'csrfToken': csrf_token}
start_json = s.post(url=start_url, data=data, headers=headers)
step_id = re.search('(?<=form/)\\d*(?=/render)', start_json.text)[0]
csrf_token = soup.find(name="meta", attrs={"itemscope": "csrfToken"}).get('content')
# get msg
data = {'stepId': step_id, 'csrfToken': csrf_token}
render = s.post(url=render_url, data=data, headers=headers)
render_info = json.loads(render.content)['entities'][0]['data']
render_info["fieldZtw"] = "1"
if grade == "BKS":
render_info["fieldDJXXyc"] = "1"
# dk
data = {
'actionId': 1,
'formData': json.dumps(render_info),
'nextUsers': '{}',
'stepId': step_id,
'timestamp': int(time.time()),
'csrfToken': csrf_token,
'lang': 'zh'
}
print(get_time(), "%15s" % username, "签到中")
headers["Connection"] = "close"
res = s.post(url=action_url, data=data, headers=headers)
time.sleep(1)
s.keep_alive = False
s.close()
time.sleep(1)
if json.loads(res.content)['ecode'] == 'SUCCEED':
return
else:
print(f"{get_time()} {username} failed.")
except Exception as e:
print(get_time(), e)
print(get_time(), str(traceback.format_exc()))
print(get_time(), "Retrying...")
time.sleep(5)
if __name__ == "__main__":
print()
print("完成情况", "https://ehall.jlu.edu.cn/taskcenter/wechat/done")
print("\n---------------------------------------------------\n")
fromMail = sys.argv[1]
mailPass = sys.argv[2]
msg = sys.argv[3]
data = []
for pre in msg.split("^^^"):
data.append(pre.split(","))
pre_time, pre_hour = get_time(need_hour=True)
print("当前时间", pre_time)
if pre_hour > 4 and pre_hour < 12:
sign_time = "早签到"
elif pre_hour > 16 and pre_hour < 24:
sign_time = "晚签到"
print(get_time(), "人数", len(data))
for i, pre_msg in enumerate(data):
print(get_time(), " %2s" % (i + 1), pre_msg[0])
print("\n")
for pre_msg in data:
usname = pre_msg[0]
passwd = pre_msg[1]
type = pre_msg[2]
mail = pre_msg[3]
need_night = pre_msg[4]
if need_night == '0' and sign_time == "晚签到":
print(get_time(), "%15s" % usname, "无需晚签到\n")
continue
while True:
print(get_time(), "%15s" % usname, sign_time)
try:
check(usname, passwd, type)
print(get_time(), "%15s" % usname, "签到完毕")
fresh_time = 1
fresh_time_equal = 1
send_message(mail, sign_time + " 成功")
break
except Exception:
print("\n error", end=' - ', flush=True)
print(str(traceback.format_exc()).replace("\n", " "))
fresh_time += 1
print("\n---------------------------------------------------\n")
time.sleep(random.randint(30, 100))
print("\n")