6
6
import requests
7
7
import time
8
8
import config
9
+ import strings
9
10
import re
10
11
11
- wechat_url = 'https://sc.ftqq.com/' + config .sckey + '.send'
12
-
13
12
14
13
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 )
17
19
18
20
19
21
today = time .localtime (time .time ())
20
- print ('Now:' , time .asctime (today ))
22
+ print ('[Info]' , ' Now:' , time .asctime (today ))
21
23
22
24
chrome_options = options .Options ()
23
25
if config .headless :
24
26
chrome_options .add_argument ('--headless' )
25
27
chrome_options .add_argument ('--disable-gpu' )
26
28
27
- print ('Launching Browser' )
29
+ print ('[Info] Launching Browser' )
28
30
if (config .driver_path != 'auto' ):
29
31
browser = webdriver .Chrome (
30
- config .driver_path , chrome_options = chrome_options )
32
+ config .driver_path , options = chrome_options )
31
33
else :
32
- browser = webdriver .Chrome (chrome_options = chrome_options )
34
+ browser = webdriver .Chrome (options = chrome_options )
33
35
34
36
browser .set_window_size (480 , 720 )
35
37
36
- print ('Logging in' )
38
+ print ('[Info] Logging in' )
37
39
browser .get ('https://id.sspu.edu.cn/cas/login' )
38
40
time .sleep (1 )
39
41
@@ -50,22 +52,22 @@ def send_wechat(msg):
50
52
try :
51
53
browser .find_element_by_class_name ('success' )
52
54
except exceptions .NoSuchElementException :
53
- print ('Login failed' )
54
- send_wechat ('Login_Failed' )
55
+ print ('[Error] Login failed' )
56
+ send_wechat (strings . get_msg_failed () )
55
57
browser .quit ()
56
58
quit (1 )
57
59
58
- print ('Login success' )
60
+ print ('[Info] Login success' )
59
61
time .sleep (0.5 )
60
62
61
- print ('Jumping to HSM page' )
63
+ print ('[Info] Jumping to HSM page' )
62
64
browser .get ('https://hsm.sspu.edu.cn/selfreport/Default.aspx' )
63
65
time .sleep (0.5 )
64
- print ('Jumping to Daily Report page' )
66
+ print ('[Info] Jumping to Daily Report page' )
65
67
browser .get ('https://hsm.sspu.edu.cn/selfreport/DayReport.aspx' )
66
68
time .sleep (1 )
67
69
68
- print ('Starting auto fill' )
70
+ print ('[Info] Starting auto fill' )
69
71
70
72
min_value = int (config .min_temperature * 10 )
71
73
max_value = int (config .max_temperature * 10 )
@@ -77,7 +79,7 @@ def send_wechat(msg):
77
79
if int (temperature * 10 ) < min_value or int (temperature * 10 ) > max_value :
78
80
temperature = randint (min_value , max_value ) / 10
79
81
80
- print ('Auto generated temperature:' , temperature )
82
+ print ('[Info] Auto generated temperature:' , temperature )
81
83
temperature_box = browser .find_element_by_id ('p1_TiWen-inputEl' )
82
84
temperature_box .clear ()
83
85
temperature_box .send_keys (str (temperature ))
@@ -99,8 +101,8 @@ def send_wechat(msg):
99
101
try :
100
102
browser .find_element_by_id ('fineui_27' )
101
103
except IndexError :
102
- print ('Submit failed' )
103
- send_wechat ('Submit_Failed' )
104
+ print ('[Error] Submit failed' )
105
+ send_wechat (strings . get_msg_failed () )
104
106
browser .quit ()
105
107
quit (0 )
106
108
@@ -109,24 +111,25 @@ def send_wechat(msg):
109
111
yes_button_1 .click ()
110
112
time .sleep (1 )
111
113
112
- for i in range (100 ):
114
+ for i in range (int ( config . timeout / 3 ) ):
113
115
time .sleep (3 )
114
116
try :
115
117
browser .find_element_by_id ('fineui_32' )
116
118
except exceptions .NoSuchElementException :
117
- print ('Waiting' )
119
+ print ('[Info] Waiting: ' + str (i * 3 ) +
120
+ ' / ' + str (config .timeout ) + ' seconds' )
118
121
continue
119
122
break
120
123
121
124
try :
122
125
browser .find_element_by_id ('fineui_32' )
123
126
except exceptions .NoSuchElementException :
124
- print ('Submit timeout' )
125
- send_wechat ('Submit_Timeout' )
127
+ print ('[Error] Submit timeout' )
128
+ send_wechat (strings . get_msg_failed () )
126
129
browser .quit ()
127
130
quit (0 )
128
131
129
- print ('Reported successfully' )
132
+ print ('[Info] Reported successfully' )
130
133
131
134
yes_button_2 = browser .find_element_by_id ('fineui_32' ) \
132
135
.find_element_by_id ('fineui_34' ) \
@@ -141,22 +144,25 @@ def send_wechat(msg):
141
144
.find_element_by_class_name ('f-datalist-list' ) \
142
145
.find_elements_by_class_name ('f-datalist-item-inner' )[0 ].text
143
146
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 ())
149
150
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
151
160
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 )
155
162
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 ))
159
165
time .sleep (1 )
160
166
161
167
browser .quit ()
162
- print ('Browser closed' )
168
+ print ('[Info] Browser closed' )
0 commit comments