Skip to content

Commit 728cf69

Browse files
committed
Added comments
1 parent 96f8881 commit 728cf69

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

daily_reporter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
def send_wechat(user_index, msg):
14+
"""Send messeage to WeChat"""
1415
wechat_url = 'http://wxpusher.zjiecode.com/api/send/message/'
1516
wechat_url += '?appToken=' + config.app_token
1617
wechat_url += '&content=' + msg
@@ -19,6 +20,7 @@ def send_wechat(user_index, msg):
1920

2021

2122
def report(user_index):
23+
"""Report for one user"""
2224
print('[Info] ' + 'Reporting for user ' + str(user_index + 1), end=', ')
2325
print('username: ' + config.users[user_index]['username'])
2426

@@ -39,6 +41,7 @@ def report(user_index):
3941

4042
browser.set_window_size(480, 720)
4143

44+
# Login
4245
print('[Info] Logging in')
4346
browser.get('https://id.sspu.edu.cn/cas/login')
4447
time.sleep(1)
@@ -53,6 +56,7 @@ def report(user_index):
5356
login_button.click()
5457
time.sleep(1)
5558

59+
# Detect login status
5660
try:
5761
browser.find_element_by_class_name('success')
5862
except exceptions.NoSuchElementException:
@@ -65,19 +69,23 @@ def report(user_index):
6569
print('[Info] Login success')
6670
time.sleep(0.5)
6771

72+
# Jump to HSM page
6873
print('[Info] Jumping to HSM page')
6974
browser.get('https://hsm.sspu.edu.cn/selfreport/Default.aspx')
7075
time.sleep(0.5)
7176

77+
# Jump to Daily Report page
7278
print('[Info] Jumping to Daily Report page')
7379
browser.get('https://hsm.sspu.edu.cn/selfreport/DayReport.aspx')
7480
time.sleep(1)
7581

82+
# Start filling
7683
print('[Info] Starting auto fill')
7784

7885
min_value = int(config.min_temperature * 10)
7986
max_value = int(config.max_temperature * 10)
8087

88+
# Generate temperature using normal distribution
8189
loc = int((min_value + max_value) / 2)
8290
scale = max_value - loc
8391
temperature = int(normal(loc=loc, scale=scale)) / 10
@@ -86,25 +94,30 @@ def report(user_index):
8694

8795
print('[Info] Auto generated temperature:', temperature)
8896

97+
# Fill temperature
8998
temperature_box = browser.find_element_by_id('p1_TiWen-inputEl')
9099
temperature_box.clear()
91100
temperature_box.send_keys(str(temperature))
92101
time.sleep(0.5)
93102

103+
# Check checkbox
94104
agree_box = browser.find_element_by_id('p1_ChengNuo-inputEl-icon')
95105
agree_box.click()
96106
time.sleep(0.5)
97107

108+
# Check checkbox
98109
condition_good = browser.find_element_by_id('p1_DangQSTZK') \
99110
.find_element_by_id('fineui_2-inputEl-icon')
100111
condition_good.click()
101112
time.sleep(0.5)
102113

114+
# Submit
103115
submit_button = browser.find_element_by_id('p1_ctl00') \
104116
.find_element_by_id('p1_ctl00_btnSubmit')
105117
submit_button.click()
106118
time.sleep(1)
107119

120+
# Detect submit status
108121
try:
109122
browser.find_element_by_id('fineui_27')
110123
except IndexError:
@@ -114,12 +127,14 @@ def report(user_index):
114127
browser.quit()
115128
return 1
116129

130+
# Confirm submit
117131
yes_button_1 = browser.find_element_by_id('fineui_34') \
118132
.find_element_by_id('fineui_36') \
119133
.find_element_by_id('fineui_37')
120134
yes_button_1.click()
121135
time.sleep(1)
122136

137+
# Waiting for submit result
123138
for i in range(int(config.timeout / 3)):
124139
time.sleep(3)
125140
try:
@@ -141,26 +156,31 @@ def report(user_index):
141156

142157
print('[Info] Reported successfully')
143158

159+
# Confirm the success message
144160
yes_button_2 = browser.find_element_by_id('fineui_39') \
145161
.find_element_by_id('fineui_41') \
146162
.find_element_by_id('fineui_42')
147163
yes_button_2.click()
148164
time.sleep(1)
149165

166+
# Check rank
150167
browser.get('https://hsm.sspu.edu.cn/selfreport/ReportHistory.aspx')
151168
time.sleep(1)
152169

170+
# Get rank data text
153171
txt = browser.find_element_by_id('Panel1_DataList1') \
154172
.find_element_by_class_name('f-datalist-list') \
155173
.find_elements_by_class_name('f-datalist-item-inner')[0].text
156174

175+
# Check whether report is successful
157176
if txt.find(strings.msg['success_msg']) == -1:
158177
print('[Error] Check failed')
159178
if config.users[user_index]['use_wechat']:
160179
send_wechat(user_index, strings.get_msg_failed(user_index))
161180
browser.quit()
162181
return 1
163182

183+
# Get rank data
164184
if re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt) != None:
165185
datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt)
166186
rank = int(datas.group(4))

0 commit comments

Comments
 (0)