|
10 | 10 | import re
|
11 | 11 |
|
12 | 12 |
|
13 |
| -def send_wechat(msg): |
| 13 | +def send_wechat(user_index, msg): |
14 | 14 | wechat_url = 'http://wxpusher.zjiecode.com/api/send/message/'
|
15 | 15 | wechat_url += '?appToken=' + config.app_token
|
16 | 16 | wechat_url += '&content=' + msg
|
17 |
| - wechat_url += '&uid=' + config.uid |
| 17 | + wechat_url += '&uid=' + config.users[user_index]['uid'] |
18 | 18 | response = requests.get(wechat_url)
|
19 | 19 |
|
20 | 20 |
|
21 |
| -today = time.localtime(time.time()) |
22 |
| -print('[Info]', 'Now:', time.asctime(today)) |
| 21 | +def report(user_index): |
| 22 | + print('[Info] ' + 'Reporting for user ' + str(user_index + 1), end=', ') |
| 23 | + print('username: ' + config.users[user_index]['username']) |
23 | 24 |
|
24 |
| -chrome_options = options.Options() |
25 |
| -if config.headless: |
26 |
| - chrome_options.add_argument('--headless') |
27 |
| - chrome_options.add_argument('--disable-gpu') |
| 25 | + today = time.localtime(time.time()) |
| 26 | + print('[Info]', 'Now:', time.asctime(today)) |
28 | 27 |
|
29 |
| -print('[Info] Launching Browser') |
30 |
| -if (config.driver_path != 'auto'): |
31 |
| - browser = webdriver.Chrome( |
32 |
| - config.driver_path, options=chrome_options) |
33 |
| -else: |
34 |
| - browser = webdriver.Chrome(options=chrome_options) |
| 28 | + chrome_options = options.Options() |
| 29 | + if config.headless: |
| 30 | + chrome_options.add_argument('--headless') |
| 31 | + chrome_options.add_argument('--disable-gpu') |
35 | 32 |
|
36 |
| -browser.set_window_size(480, 720) |
| 33 | + print('[Info] Launching Browser') |
| 34 | + if (config.driver_path != 'auto'): |
| 35 | + browser = webdriver.Chrome( |
| 36 | + config.driver_path, options=chrome_options) |
| 37 | + else: |
| 38 | + browser = webdriver.Chrome(options=chrome_options) |
37 | 39 |
|
38 |
| -print('[Info] Logging in') |
39 |
| -browser.get('https://id.sspu.edu.cn/cas/login') |
40 |
| -time.sleep(1) |
| 40 | + browser.set_window_size(480, 720) |
41 | 41 |
|
42 |
| -username_box = browser.find_element_by_id('username') |
43 |
| -username_box.send_keys(config.username) |
44 |
| -password_box = browser.find_element_by_id('password') |
45 |
| -password_box.send_keys(config.password) |
46 |
| -time.sleep(0.5) |
| 42 | + print('[Info] Logging in') |
| 43 | + browser.get('https://id.sspu.edu.cn/cas/login') |
| 44 | + time.sleep(1) |
47 | 45 |
|
48 |
| -login_button = browser.find_element_by_class_name('submit_button') |
49 |
| -login_button.click() |
50 |
| -time.sleep(1) |
| 46 | + username_box = browser.find_element_by_id('username') |
| 47 | + username_box.send_keys(config.users[user_index]['username']) |
| 48 | + password_box = browser.find_element_by_id('password') |
| 49 | + password_box.send_keys(config.users[user_index]['password']) |
| 50 | + time.sleep(0.5) |
51 | 51 |
|
52 |
| -try: |
53 |
| - browser.find_element_by_class_name('success') |
54 |
| -except exceptions.NoSuchElementException: |
55 |
| - print('[Error] Login failed') |
56 |
| - send_wechat(strings.get_msg_failed()) |
57 |
| - browser.quit() |
58 |
| - quit(1) |
59 |
| - |
60 |
| -print('[Info] Login success') |
61 |
| -time.sleep(0.5) |
62 |
| - |
63 |
| -print('[Info] Jumping to HSM page') |
64 |
| -browser.get('https://hsm.sspu.edu.cn/selfreport/Default.aspx') |
65 |
| -time.sleep(0.5) |
66 |
| -print('[Info] Jumping to Daily Report page') |
67 |
| -browser.get('https://hsm.sspu.edu.cn/selfreport/DayReport.aspx') |
68 |
| -time.sleep(1) |
69 |
| - |
70 |
| -print('[Info] Starting auto fill') |
71 |
| - |
72 |
| -min_value = int(config.min_temperature * 10) |
73 |
| -max_value = int(config.max_temperature * 10) |
74 |
| - |
75 |
| -loc = int((min_value + max_value) / 2) |
76 |
| -scale = max_value - loc |
77 |
| -temperature = int(normal(loc=loc, scale=scale)) / 10 |
78 |
| - |
79 |
| -if int(temperature * 10) < min_value or int(temperature * 10) > max_value: |
80 |
| - temperature = randint(min_value, max_value) / 10 |
81 |
| - |
82 |
| -print('[Info] Auto generated temperature:', temperature) |
83 |
| -temperature_box = browser.find_element_by_id('p1_TiWen-inputEl') |
84 |
| -temperature_box.clear() |
85 |
| -temperature_box.send_keys(str(temperature)) |
86 |
| -time.sleep(0.5) |
87 |
| - |
88 |
| -agree_box = browser.find_element_by_id('p1_ChengNuo-inputEl-icon') |
89 |
| -agree_box.click() |
90 |
| -time.sleep(0.5) |
91 |
| - |
92 |
| -condition_good = browser.find_element_by_id('fineui_2-inputEl-icon') |
93 |
| -condition_good.click() |
94 |
| -time.sleep(0.5) |
95 |
| - |
96 |
| -submit_button = browser.find_element_by_id('p1_ctl00') \ |
97 |
| - .find_element_by_id('p1_ctl00_btnSubmit') |
98 |
| -submit_button.click() |
99 |
| -time.sleep(1) |
100 |
| - |
101 |
| -try: |
102 |
| - browser.find_element_by_id('fineui_27') |
103 |
| -except IndexError: |
104 |
| - print('[Error] Submit failed') |
105 |
| - send_wechat(strings.get_msg_failed()) |
106 |
| - browser.quit() |
107 |
| - quit(0) |
108 |
| - |
109 |
| -yes_button_1 = browser.find_element_by_id('fineui_27') \ |
110 |
| - .find_element_by_id('fineui_30') |
111 |
| -yes_button_1.click() |
112 |
| -time.sleep(1) |
| 52 | + login_button = browser.find_element_by_class_name('submit_button') |
| 53 | + login_button.click() |
| 54 | + time.sleep(1) |
113 | 55 |
|
114 |
| -for i in range(int(config.timeout / 3)): |
115 |
| - time.sleep(3) |
116 | 56 | try:
|
117 |
| - browser.find_element_by_id('fineui_32') |
| 57 | + browser.find_element_by_class_name('success') |
118 | 58 | except exceptions.NoSuchElementException:
|
119 |
| - print('[Info] Waiting: ' + str(i * 3) + |
120 |
| - ' / ' + str(config.timeout) + ' seconds') |
121 |
| - continue |
122 |
| - break |
123 |
| - |
124 |
| -try: |
125 |
| - browser.find_element_by_id('fineui_32') |
126 |
| -except exceptions.NoSuchElementException: |
127 |
| - print('[Error] Submit timeout') |
128 |
| - send_wechat(strings.get_msg_failed()) |
129 |
| - browser.quit() |
130 |
| - quit(0) |
| 59 | + print('[Error] Login failed') |
| 60 | + send_wechat(user_index, strings.get_msg_failed(user_index)) |
| 61 | + browser.quit() |
| 62 | + quit(1) |
| 63 | + |
| 64 | + print('[Info] Login success') |
| 65 | + time.sleep(0.5) |
| 66 | + |
| 67 | + print('[Info] Jumping to HSM page') |
| 68 | + browser.get('https://hsm.sspu.edu.cn/selfreport/Default.aspx') |
| 69 | + time.sleep(0.5) |
| 70 | + print('[Info] Jumping to Daily Report page') |
| 71 | + browser.get('https://hsm.sspu.edu.cn/selfreport/DayReport.aspx') |
| 72 | + time.sleep(1) |
| 73 | + |
| 74 | + print('[Info] Starting auto fill') |
| 75 | + |
| 76 | + min_value = int(config.min_temperature * 10) |
| 77 | + max_value = int(config.max_temperature * 10) |
131 | 78 |
|
132 |
| -print('[Info] Reported successfully') |
| 79 | + loc = int((min_value + max_value) / 2) |
| 80 | + scale = max_value - loc |
| 81 | + temperature = int(normal(loc=loc, scale=scale)) / 10 |
133 | 82 |
|
134 |
| -yes_button_2 = browser.find_element_by_id('fineui_32') \ |
135 |
| - .find_element_by_id('fineui_34') \ |
136 |
| - .find_element_by_id('fineui_35') |
137 |
| -yes_button_2.click() |
138 |
| -time.sleep(1) |
| 83 | + if int(temperature * 10) < min_value or int(temperature * 10) > max_value: |
| 84 | + temperature = randint(min_value, max_value) / 10 |
139 | 85 |
|
140 |
| -browser.get('https://hsm.sspu.edu.cn/selfreport/ReportHistory.aspx') |
141 |
| -time.sleep(1) |
| 86 | + print('[Info] Auto generated temperature:', temperature) |
| 87 | + temperature_box = browser.find_element_by_id('p1_TiWen-inputEl') |
| 88 | + temperature_box.clear() |
| 89 | + temperature_box.send_keys(str(temperature)) |
| 90 | + time.sleep(0.5) |
142 | 91 |
|
143 |
| -txt = browser.find_element_by_id('Panel1_DataList1') \ |
144 |
| - .find_element_by_class_name('f-datalist-list') \ |
145 |
| - .find_elements_by_class_name('f-datalist-item-inner')[0].text |
| 92 | + agree_box = browser.find_element_by_id('p1_ChengNuo-inputEl-icon') |
| 93 | + agree_box.click() |
| 94 | + time.sleep(0.5) |
| 95 | + |
| 96 | + condition_good = browser.find_element_by_id('fineui_2-inputEl-icon') |
| 97 | + condition_good.click() |
| 98 | + time.sleep(0.5) |
| 99 | + |
| 100 | + submit_button = browser.find_element_by_id('p1_ctl00') \ |
| 101 | + .find_element_by_id('p1_ctl00_btnSubmit') |
| 102 | + submit_button.click() |
| 103 | + time.sleep(1) |
| 104 | + |
| 105 | + try: |
| 106 | + browser.find_element_by_id('fineui_27') |
| 107 | + except IndexError: |
| 108 | + print('[Error] Submit failed') |
| 109 | + send_wechat(user_index, strings.get_msg_failed(user_index)) |
| 110 | + browser.quit() |
| 111 | + quit(0) |
| 112 | + |
| 113 | + yes_button_1 = browser.find_element_by_id('fineui_27') \ |
| 114 | + .find_element_by_id('fineui_30') |
| 115 | + yes_button_1.click() |
| 116 | + time.sleep(1) |
| 117 | + |
| 118 | + for i in range(int(config.timeout / 3)): |
| 119 | + time.sleep(3) |
| 120 | + try: |
| 121 | + browser.find_element_by_id('fineui_32') |
| 122 | + except exceptions.NoSuchElementException: |
| 123 | + print('[Info] Waiting: ' + str(i * 3) + |
| 124 | + ' / ' + str(config.timeout) + ' seconds') |
| 125 | + continue |
| 126 | + break |
| 127 | + |
| 128 | + try: |
| 129 | + browser.find_element_by_id('fineui_32') |
| 130 | + except exceptions.NoSuchElementException: |
| 131 | + print('[Error] Submit timeout') |
| 132 | + send_wechat(user_index, strings.get_msg_failed(user_index)) |
| 133 | + browser.quit() |
| 134 | + quit(0) |
| 135 | + |
| 136 | + print('[Info] Reported successfully') |
| 137 | + |
| 138 | + yes_button_2 = browser.find_element_by_id('fineui_32') \ |
| 139 | + .find_element_by_id('fineui_34') \ |
| 140 | + .find_element_by_id('fineui_35') |
| 141 | + yes_button_2.click() |
| 142 | + time.sleep(1) |
| 143 | + |
| 144 | + browser.get('https://hsm.sspu.edu.cn/selfreport/ReportHistory.aspx') |
| 145 | + time.sleep(1) |
| 146 | + |
| 147 | + txt = browser.find_element_by_id('Panel1_DataList1') \ |
| 148 | + .find_element_by_class_name('f-datalist-list') \ |
| 149 | + .find_elements_by_class_name('f-datalist-item-inner')[0].text |
| 150 | + |
| 151 | + if txt.find(strings.msg['success_msg']) == -1: |
| 152 | + print('[Error] Check failed') |
| 153 | + send_wechat(user_index, strings.get_msg_failed(user_index)) |
| 154 | + browser.quit() |
| 155 | + quit(1) |
| 156 | + |
| 157 | + if re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt) != None: |
| 158 | + datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?(\d+).*?\)$', txt) |
| 159 | + rank = int(datas.group(4)) |
| 160 | + else: |
| 161 | + print('[Warring] Check rank failed') |
| 162 | + datas = re.match(r'^(\d+)-(\d+)-(\d+)\(.*?\)$', txt) |
| 163 | + rank = None |
| 164 | + |
| 165 | + date = datas.group(1) + '-' + datas.group(2) + '-' + datas.group(3) |
| 166 | + |
| 167 | + print('[Info] ' + 'Date: ' + date + ', Rank: ' + str(rank)) |
| 168 | + send_wechat(user_index, strings.get_msg_success( |
| 169 | + user_index, date, rank, temperature)) |
| 170 | + time.sleep(1) |
146 | 171 |
|
147 |
| -if txt.find(strings.msg['success_msg']) == -1: |
148 |
| - print('[Error] Check failed') |
149 |
| - send_wechat(strings.get_msg_failed()) |
150 | 172 | browser.quit()
|
151 |
| - quit(1) |
| 173 | + print('[Info] Browser closed') |
152 | 174 |
|
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 |
160 | 175 |
|
161 |
| -date = datas.group(1) + '-' + datas.group(2) + '-' + datas.group(3) |
| 176 | +print('[Info] Task started\n') |
162 | 177 |
|
163 |
| -print('[Info] ' + 'Date: ' + date + ', Rank: ' + str(rank)) |
164 |
| -send_wechat(strings.get_msg_success(date, rank, temperature)) |
165 |
| -time.sleep(1) |
| 178 | +for user_index in range(len(config.users)): |
| 179 | + report(user_index) |
| 180 | + print() |
| 181 | + time.sleep(5) |
166 | 182 |
|
167 |
| -browser.quit() |
168 |
| -print('[Info] Browser closed') |
| 183 | +print('[Info] Task done') |
0 commit comments