-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launcher.py
38 lines (34 loc) · 1.33 KB
/
Launcher.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by gcdd1993 on 2022/11/19
# Launcher.py
from yaml import load
from SSLCheck import SSLCheck
from notify.QywxNotifyImpl import QywxNotifyImpl
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
if __name__ == '__main__':
with open("config.yaml", "r", encoding="UTF-8") as f:
conf = load(f, Loader=Loader)
print(f"读取配置文件 {conf}")
# 创建SSLCheck实例
ssl_checker_list = []
for domain in conf["domains"]:
ssl_checker_list.append(SSLCheck(domain))
# 开始遍历检测SSL证书,并构造通知消息
msg = ""
for ssl_checker in ssl_checker_list:
expire_in_days = ssl_checker.get_ssl_time()
msg += f"域名 {ssl_checker.domain} 还有 {expire_in_days} 天到期\n"
print(msg)
# 创建notify实例
notify_list = []
for n in conf["notify"]:
if n["type"] == "QYWX":
mentioned_list = n.get("mentioned", []).get("name", [])
mentioned_mobile_list = n.get("mentioned", []).get("phone", [])
notify_list.append(QywxNotifyImpl(n["key"], mentioned_list, mentioned_mobile_list))
for notify in notify_list:
notify.notify(msg)