From 5c142409263fea209ae89c4525c67c96859886b5 Mon Sep 17 00:00:00 2001 From: takidog Date: Sat, 18 Jan 2020 20:41:01 +0800 Subject: [PATCH] Fix issue#76 If leave submit are not delay, no reason is required --- src/crawler/leave_crawler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/crawler/leave_crawler.py b/src/crawler/leave_crawler.py index 8317fab..68c0baa 100644 --- a/src/crawler/leave_crawler.py +++ b/src/crawler/leave_crawler.py @@ -215,8 +215,10 @@ def leave_submit(session, leave_data, proof_file=None, proof_file_name="test.jpg req = session.post(url=main_url, data=form_data) root = etree.HTML(req.text) try: - if root.xpath("//script[@language='javascript']")[0].text.find('alert') >= 0: - return error_code.LEAVE_SUBMIT_WRONG_DATE # 日期不對//或是不再學期中 + alert = root.xpath("//script[@language='javascript']")[0].text + if alert.find('alert') >= 0: + if alert.find('不在學期間') >= 0: # 延遲請假也會用alert + return error_code.LEAVE_SUBMIT_WRONG_DATE # 日期不對//或是不再學期中 except: pass @@ -226,7 +228,7 @@ def leave_submit(session, leave_data, proof_file=None, proof_file_name="test.jpg global_form_data['ctl00$ContentPlaceHolder1$CK001$RadioButtonListOption'] = leave_data['leaveType'] time_code = root.xpath( "//div[@id='ContentPlaceHolder1_CK001_UpdatePanel2']//tr") - if leave_data.get('delayReasonText', False): + if leave_data.get('delayReasonText', False) and req.text.find('延遲理由') > -1: global_form_data['ctl00$ContentPlaceHolder1$CK001$TextBoxDelayReason'] = leave_data.get( 'delayReasonText', '') need_click_button_data = []