| 123456789101112131415161718192021222324252627282930313233 |
- import json
- import logging
- import sys
- import conf
- from conf import path, text
- from robot.chrome import Robot
- from lib.send import Sender
- if __name__ == '__main__':
- logging.basicConfig(level=logging.INFO, filename=path.log,
- format='%(asctime)s [%(levelname)s] %(message)s')
- sender = Sender(conf.smtp, conf.wechat)
- robot = Robot()
- with open(sys.argv[1]) as f:
- users = json.load(f)
- for user in users:
- try:
- result = robot.punch(**user['punch'])
- 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.failed
- info = user['punch']['username'] + result
- logging.exception(info, exc_info=e)
- finally:
- sender.send(result, text.subject, **user['contact'])
- print(info)
|