This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
92 lines (77 loc) · 2.65 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'''
Author: Yaaprogrammer
Date: 2022-04-14 20:54:28
LastEditors: Yaaprogrammer
LastEditTime: 2022-05-07 20:44:41
Copyright (c) 2022 by Yaaprogrammer, All Rights Reserved.
'''
import argparse
import traceback
import urllib3
from tenacity import retry, stop_after_attempt
from helper import Helper
from utils import Banner, Configuration, EmailController, MyLogger, logger
def run():
config = Configuration()
helper = Helper()
if (config.getProperty("args.check_only") is True):
helper.check()
else:
helper.run()
def parseArgs():
args = argparse.ArgumentParser(description='ZZU疫情填报小助手 ')
args.add_argument("-n",
'--no-email',
help=u"不发送邮件",
default=False,
action='store_true')
args.add_argument('-l',
"--log-no-file",
help='不输出日志到文件',
default=False,
action='store_true')
args.add_argument("-c",
"--check-only",
help="仅进行检查,不进行填报",
default=False,
action='store_true')
args = args.parse_args()
config = Configuration()
argDict = vars(args)
config.addProperty('args', argDict)
if config.getProperty("args.no_email") is True:
config.setProperty("smtp.enable", False)
logger.info("命令行参数: 不发送邮件")
if config.getProperty("args.log_no_file") is True:
config.setProperty("logger.enable", False)
logger.info("命令行参数: 不输出日志到文件")
if config.getProperty("args.check_only") is True:
logger.info("命令行参数: 仅进行检查,不进行填报")
def disableSSLWarning():
config = Configuration()
if (not config.getProperty("crawler.verify")):
urllib3.disable_warnings()
def getRetryTimes():
config = Configuration()
return config.getProperty("retry.times")
@retry(stop=stop_after_attempt(getRetryTimes()))
@logger.catch
def main(event, context):
banner = Banner()
banner.printBanner()
if event and context:
logger.info("从云函数启动")
logger.info(f"event:{event} context:{context}")
logger.success("Start main process")
parseArgs()
MyLogger.startLogging()
disableSSLWarning()
run()
if __name__ == "__main__":
try:
main("", "")
except Exception:
message = traceback.format_exc()
emailController = EmailController()
emailController.send(title="未知异常", html=message)
logger.exception("未知异常")