Skip to content

Commit fe02eaf

Browse files
committed
Changed WeChat push service
Changed from sc.ftqq.com to wxpusher.zjiecode.com
1 parent b520819 commit fe02eaf

File tree

4 files changed

+86
-38
lines changed

4 files changed

+86
-38
lines changed

config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
min_temperature = 35.5
55
max_temperature = 36.9
66

7-
sckey = 'SCU0123456789abcdef0123456789abcdef0123456789abcdef012'
7+
timeout = 600
88

99
driver_path = 'auto'
1010
headless = False
11+
12+
app_token = 'AT_ABCDEF0123456789abcdef0123456789'
13+
uid = 'UID_ABCDEF0123456789abcdef012345'

daily_reporter.py

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,36 @@
66
import requests
77
import time
88
import config
9+
import strings
910
import re
1011

11-
wechat_url = 'https://sc.ftqq.com/' + config.sckey + '.send'
12-
1312

1413
def send_wechat(msg):
15-
send_url = wechat_url + '?text=' + msg
16-
response = requests.get(send_url)
14+
wechat_url = 'http://wxpusher.zjiecode.com/api/send/message/'
15+
wechat_url += '?appToken=' + config.app_token
16+
wechat_url += '&content=' + msg
17+
wechat_url += '&uid=' + config.uid
18+
response = requests.get(wechat_url)
1719

1820

1921
today = time.localtime(time.time())
20-
print('Now:', time.asctime(today))
22+
print('[Info]', 'Now:', time.asctime(today))
2123

2224
chrome_options = options.Options()
2325
if config.headless:
2426
chrome_options.add_argument('--headless')
2527
chrome_options.add_argument('--disable-gpu')
2628

27-
print('Launching Browser')
29+
print('[Info] Launching Browser')
2830
if (config.driver_path != 'auto'):
2931
browser = webdriver.Chrome(
30-
config.driver_path, chrome_options=chrome_options)
32+
config.driver_path, options=chrome_options)
3133
else:
32-
browser = webdriver.Chrome(chrome_options=chrome_options)
34+
browser = webdriver.Chrome(options=chrome_options)
3335

3436
browser.set_window_size(480, 720)
3537

36-
print('Logging in')
38+
print('[Info] Logging in')
3739
browser.get('https://id.sspu.edu.cn/cas/login')
3840
time.sleep(1)
3941

@@ -50,22 +52,22 @@ def send_wechat(msg):
5052
try:
5153
browser.find_element_by_class_name('success')
5254
except exceptions.NoSuchElementException:
53-
print('Login failed')
54-
send_wechat('Login_Failed')
55+
print('[Error] Login failed')
56+
send_wechat(strings.get_msg_failed())
5557
browser.quit()
5658
quit(1)
5759

58-
print('Login success')
60+
print('[Info] Login success')
5961
time.sleep(0.5)
6062

61-
print('Jumping to HSM page')
63+
print('[Info] Jumping to HSM page')
6264
browser.get('https://hsm.sspu.edu.cn/selfreport/Default.aspx')
6365
time.sleep(0.5)
64-
print('Jumping to Daily Report page')
66+
print('[Info] Jumping to Daily Report page')
6567
browser.get('https://hsm.sspu.edu.cn/selfreport/DayReport.aspx')
6668
time.sleep(1)
6769

68-
print('Starting auto fill')
70+
print('[Info] Starting auto fill')
6971

7072
min_value = int(config.min_temperature * 10)
7173
max_value = int(config.max_temperature * 10)
@@ -77,7 +79,7 @@ def send_wechat(msg):
7779
if int(temperature * 10) < min_value or int(temperature * 10) > max_value:
7880
temperature = randint(min_value, max_value) / 10
7981

80-
print('Auto generated temperature:', temperature)
82+
print('[Info] Auto generated temperature:', temperature)
8183
temperature_box = browser.find_element_by_id('p1_TiWen-inputEl')
8284
temperature_box.clear()
8385
temperature_box.send_keys(str(temperature))
@@ -99,8 +101,8 @@ def send_wechat(msg):
99101
try:
100102
browser.find_element_by_id('fineui_27')
101103
except IndexError:
102-
print('Submit failed')
103-
send_wechat('Submit_Failed')
104+
print('[Error] Submit failed')
105+
send_wechat(strings.get_msg_failed())
104106
browser.quit()
105107
quit(0)
106108

@@ -109,24 +111,25 @@ def send_wechat(msg):
109111
yes_button_1.click()
110112
time.sleep(1)
111113

112-
for i in range(100):
114+
for i in range(int(config.timeout / 3)):
113115
time.sleep(3)
114116
try:
115117
browser.find_element_by_id('fineui_32')
116118
except exceptions.NoSuchElementException:
117-
print('Waiting')
119+
print('[Info] Waiting: ' + str(i * 3) +
120+
' / ' + str(config.timeout) + ' seconds')
118121
continue
119122
break
120123

121124
try:
122125
browser.find_element_by_id('fineui_32')
123126
except exceptions.NoSuchElementException:
124-
print('Submit timeout')
125-
send_wechat('Submit_Timeout')
127+
print('[Error] Submit timeout')
128+
send_wechat(strings.get_msg_failed())
126129
browser.quit()
127130
quit(0)
128131

129-
print('Reported successfully')
132+
print('[Info] Reported successfully')
130133

131134
yes_button_2 = browser.find_element_by_id('fineui_32') \
132135
.find_element_by_id('fineui_34') \
@@ -141,22 +144,25 @@ def send_wechat(msg):
141144
.find_element_by_class_name('f-datalist-list') \
142145
.find_elements_by_class_name('f-datalist-item-inner')[0].text
143146

144-
datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt)
145-
146-
if datas == None:
147-
print('Check failed')
148-
send_wechat('Check_Failed')
147+
if txt.find(strings.msg['success_msg']) == -1:
148+
print('[Error] Check failed')
149+
send_wechat(strings.get_msg_failed())
149150
browser.quit()
150-
quit(0)
151+
quit(1)
152+
153+
if re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt) != None:
154+
datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt)
155+
rank = int(datas.group(4))
156+
else:
157+
print('[Warring] Check rank failed')
158+
datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?\)$', txt)
159+
rank = None
151160

152-
res_date = datas.group(1) + '-' + datas.group(2) + '-' + datas.group(3)
153-
res_date_wechat = datas.group(1) + '.' + datas.group(2) + '.' + datas.group(3)
154-
rank = int(datas.group(4))
161+
date = datas.group(1) + '-' + datas.group(2) + '-' + datas.group(3)
155162

156-
print('Date: ' + res_date + ', Rank: ' + str(rank))
157-
send_wechat('Successfully' + '_' + res_date_wechat +
158-
'_' + str(temperature) + '_' + str(rank))
163+
print('[Info] ' + 'Date: ' + date + ', Rank: ' + str(rank))
164+
send_wechat(strings.get_msg_success(date, rank, temperature))
159165
time.sleep(1)
160166

161167
browser.quit()
162-
print('Browser closed')
168+
print('[Info] Browser closed')

scheduler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def job():
1111

1212
schedule.every().day.at('00:30').do(job)
1313
schedule.every().day.at('07:30').do(job)
14-
schedule.every().day.at('13:30').do(job)
1514

1615
print('Started scheduler')
1716

strings.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import config
2+
import time
3+
4+
msg = {}
5+
6+
# WeChat message strings
7+
msg['success'] = '报送成功!'
8+
9+
msg['number'] = '报送学号:'
10+
msg['date'] = '报送日期:'
11+
msg['time'] = '成功时间:'
12+
msg['rank'] = '当日排名:'
13+
msg['temperature'] = '报送体温:'
14+
15+
msg['failed_msg'] = '报送失败,请手动报送!'
16+
msg['failed_time'] = '失败时间:'
17+
18+
# Website strings
19+
msg['success_msg'] = '已填报'
20+
21+
22+
def get_msg_success(date, rank, temp):
23+
now = time.localtime(time.time())
24+
res = msg['success'] + '%0a' + '%0a'
25+
res += msg['number'] + str(config.username) + '%0a'
26+
res += msg['date'] + date + '%0a'
27+
res += msg['time'] + str(now[3]) + ':' + str(now[4]) + '%0a'
28+
res += msg['rank'] + str(rank) + '%0a'
29+
res += msg['temperature'] + str(temp)
30+
return res
31+
32+
33+
def get_msg_failed():
34+
now = time.localtime(time.time())
35+
res = msg['failed_msg'] + '%0a' + '%0a'
36+
res += msg['number'] + str(config.username) + '%0a'
37+
res += msg['date'] + str(now[0]) + '-' + \
38+
str(now[1]) + '-' + str(now[2]) + '%0a'
39+
res += msg['failed_time'] + str(now[3]) + ':' + str(now[4])
40+
return res

0 commit comments

Comments
 (0)