Browse Source

一些小修改

ignatz 3 years ago
parent
commit
e0d2a9a50d
4 changed files with 24 additions and 24 deletions
  1. 2 1
      .gitignore
  2. 11 13
      conf.py
  3. 10 5
      punch.py
  4. 1 5
      robot/chrome.py

+ 2 - 1
.gitignore

@@ -1,3 +1,4 @@
 __pycache__/
 log/
-driver/
+driver/
+conf.json

+ 11 - 13
conf.py

@@ -1,19 +1,17 @@
 import os
 import sys
+import json
 from os.path import join
 
-smtp = {
-    "sender": "疫情防控通小助手 <ncov_robot@163.com>",
-    "server": "smtp.163.com",
-    "port": 465,
-    "user": "ncov_robot@163.com",
-    "password": "***REMOVED***"
-}
-wechat = {
-    "corpid": "***REMOVED***",
-    "corpsecret": "***REMOVED***",
-    "agentid": "***REMOVED***"
-}
+
+try:
+    with open('conf.json') as f:
+        data = json.load(f)
+        smtp = data.get('smtp')
+        wechat = data.get('wechat')
+except:
+    smtp = None
+    wechat = None
 
 class path:
     base = os.path.dirname(sys.argv[0])
@@ -27,6 +25,6 @@ class path:
 
 class text:
     subject = '疫情防控通自动打卡结果'
-    exc = '自动打卡异常!'
+    failed = '自动打卡失败!'
     ok = '自动打卡成功'
     already = '已打卡过'

+ 10 - 5
punch.py

@@ -17,12 +17,17 @@ if __name__ == '__main__':
     for user in users:
         try:
             result = robot.punch(**user['punch'])
-            logging.info('result: ' + result)
+            if '成功' in result:
+                result = text.ok
+            if '已提交过' in result:
+                result = text.already
+            info = user['punch']['username'] + result
+            logging.info(info)
         except Exception as e:
-            result = text.exc
-            logging.exception(result, exc_info=e)
+            result = text.failed
+            info = user['punch']['username'] + result
+            logging.exception(info, exc_info=e)
         finally:
-            result = user['punch']['username'] + result
             sender.send(result, text.subject, **user['contact'])
-            print(result)
+            print(info)
 

+ 1 - 5
robot/chrome.py

@@ -5,7 +5,7 @@ from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC
 import logging
 
-from conf import text, path
+from conf import path
 from . import url, loc
 
 
@@ -45,10 +45,6 @@ class Robot:
             self.wait_to_click(loc.submit_confirm_button).click()
             self.wait.until(EC.invisibility_of_element_located(loc.loading))
         result = self.wait.until(EC.visibility_of_element_located(loc.result)).text
-        if '成功' in result:
-            result = text.ok
-        if '已提交过' in result:
-            result = text.already
         return result
     
     def quit(self):