68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import signal
|
|
from datetime import datetime
|
|
import sys
|
|
import time
|
|
import yaml
|
|
# from SendBot import SendToFeishu
|
|
from media.common import run
|
|
from media.freebuf import freebuf_main
|
|
from media.xianzhi import xianzhi_main
|
|
from GotoSend_4hou import Src_4hou
|
|
from GotoSend_anquanke import Src_anquanke
|
|
from GotoSend_doonsec import Src_doonsec
|
|
|
|
# 加载参数
|
|
def get_params():
|
|
with open('./config.yaml', 'r', encoding="utf-8") as file:
|
|
config = yaml.safe_load(file)
|
|
sleep_time = f"{config['sleep_time']}"
|
|
s_hour = int(f"{config['s_hour']}")
|
|
e_hour = int(f"{config['e_hour']}")
|
|
c_hour = int(f"{config['c_hour']}")
|
|
|
|
return sleep_time, s_hour, e_hour, c_hour
|
|
|
|
sleep_time, s_hour, e_hour, c_hour = get_params()
|
|
|
|
def crab_job():
|
|
print("正在启动各爬虫并获取资源中...")
|
|
run()
|
|
xianzhi_main()
|
|
freebuf_main()
|
|
|
|
def send_job():
|
|
Src_4hou(s_hour, e_hour)
|
|
Src_anquanke(s_hour, e_hour)
|
|
Src_doonsec(s_hour, e_hour)
|
|
|
|
def signal_handler(sig, frame):
|
|
print("接收到退出信号,程序即将退出...")
|
|
sys.exit(0)
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
|
signal.signal(signal.SIGTERM, signal_handler) # kill命令
|
|
|
|
def main_loop():
|
|
while True:
|
|
try:
|
|
# 获取当前时间
|
|
now = datetime.now()
|
|
# 检查是否为特定时间点
|
|
if now.hour == c_hour and now.minute == 5:
|
|
crab_job()
|
|
send_job()
|
|
print("执行完毕,等待下一次执行...")
|
|
else:
|
|
pass
|
|
# print("正在等待执行...")
|
|
# print("等待间隔:", int(sleep_time))
|
|
time.sleep(int(sleep_time)) # 每隔35秒执行一次
|
|
except Exception as e:
|
|
print(f"发生错误: {e} ,程序已暂停")
|
|
# SendToFeishu(f"发生错误: {e} ,程序已退出", "报错信息")
|
|
exit()
|
|
|
|
if __name__ == "__main__":
|
|
print("程序正在运行当中。")
|
|
main_loop() |