大型更新优化
This commit is contained in:
parent
71cc3b4d22
commit
fd7a51f24b
167
Core.py
167
Core.py
@ -58,103 +58,130 @@ webhook_url_once, timestamp_once, sign_once = gen_sign()
|
||||
e_hour, time_choice, choice, fs_activate, wx_activate, ding_activate, lx_activate, url_web = get_core_config()
|
||||
|
||||
|
||||
def check_avaliable(info_long, info_short, title, webhook_url, timestamp, sign):
|
||||
def check_avaliable(info_long, info_short, title):
|
||||
if info_long: # 发送完整文章相关内容
|
||||
# logger.info(f"{title} 递送中(飞书):")
|
||||
result = SendToFeishu(info_long, title, webhook_url, timestamp, sign)
|
||||
logger.info(result)
|
||||
time.sleep(15)
|
||||
else:
|
||||
pass
|
||||
if fs_activate == "True":
|
||||
# logger.info(f"{title} 递送中(飞书):")
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
result = SendToFeishu(info_long, title, webhook_url, timestamp, sign)
|
||||
logger.info(result)
|
||||
time.sleep(15)
|
||||
|
||||
if info_short: # 发送精简文章相关内容
|
||||
# 企业微信相关
|
||||
if wx_activate == "True":
|
||||
# logger.info(f"{title} 递送中(企业微信):")
|
||||
result = SendToWX(info_short, title)
|
||||
logger.info(result)
|
||||
for info in info_short:
|
||||
result = SendToWX(info, title)
|
||||
logger.info(result)
|
||||
time.sleep(15)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
# 钉钉相关
|
||||
if ding_activate == "True":
|
||||
# logger.info(f"{title} 递送中(钉钉):")
|
||||
# result = SendToWX(info_short, title) # 待完善
|
||||
logger.info(result)
|
||||
# for info in info_short: # 开发中,暂未实现
|
||||
# result = SendToDD(info, title)
|
||||
# logger.info(result)
|
||||
time.sleep(15)
|
||||
else:
|
||||
pass
|
||||
if not info_long and not info_short:
|
||||
logger.info(f"{title}数据为空,跳过执行。")
|
||||
|
||||
def send_job_RSS(time_1):
|
||||
Doonsec_switch, Doonsec = get_kewords_config('Doonsec')
|
||||
# print(f"当前配置信息:Doonsec_switch:{Doonsec_switch}")
|
||||
# 爬取数据
|
||||
seebug_main()
|
||||
anquanke_main()
|
||||
huawei_main()
|
||||
doonsec_main()
|
||||
qianxin_main()
|
||||
freebuf_main()
|
||||
xianzhi_main()
|
||||
M_4hou_main()
|
||||
|
||||
# 分析各个数据源的结果(输出长结果)
|
||||
result_4hou_long = Src_4hou(time_1, False)
|
||||
result_anquanke_long = Src_anquanke(time_1, False)
|
||||
result_doonsec_long = Src_doonsec(False, Doonsec_switch, Doonsec)
|
||||
# print(result_doonsec_long)
|
||||
result_xianzhi_long = Src_xianzhi(time_1, False)
|
||||
result_freebuf_long = Src_freebuf(time_1, False)
|
||||
result_qianxin_long = Src_qianxin(time_1, False)
|
||||
result_seebug_long = Src_seebug(time_1, False)
|
||||
# 分析各个数据源的结果(输出短结果)
|
||||
result_4hou_short = Src_4hou(time_1, True)
|
||||
result_anquanke_short = Src_anquanke(time_1, True)
|
||||
result_doonsec_short = Src_doonsec(True, Doonsec_switch, Doonsec)
|
||||
result_xianzhi_short = Src_xianzhi(time_1, True)
|
||||
result_freebuf_short = Src_freebuf(time_1, True)
|
||||
result_qianxin_short = Src_qianxin(time_1, True)
|
||||
result_seebug_short = Src_seebug(time_1, True)
|
||||
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
|
||||
check_avaliable(result_4hou_long, result_4hou_short, "嘶吼资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_anquanke_long, result_anquanke_short, "安全客资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_doonsec_long, result_doonsec_short, "洞见微信安全资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_xianzhi_long, result_xianzhi_short, "先知社区资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_freebuf_long, result_freebuf_short, "FreeBuf资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_qianxin_long, result_qianxin_short, "奇安信攻防社区资讯", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_seebug_long, result_seebug_short, "Seebug社区资讯", webhook_url, timestamp, sign)
|
||||
# Seebug数据获取分发
|
||||
seebug_main()
|
||||
seebug_results = Src_seebug(time_1)
|
||||
if seebug_results != False:
|
||||
result_seebug_long, result_seebug_short = seebug_results
|
||||
check_avaliable(result_seebug_long, result_seebug_short, "Seebug社区资讯")
|
||||
else:
|
||||
logger.info("Seebug数据为空,跳过执行。")
|
||||
|
||||
# 安全客数据获取分发
|
||||
anquanke_main()
|
||||
anquanke_results = Src_anquanke(time_1)
|
||||
if anquanke_results != False:
|
||||
result_anquanke_long, result_anquanke_short = anquanke_results
|
||||
check_avaliable(result_anquanke_long, result_anquanke_short, "安全客资讯")
|
||||
else:
|
||||
logger.info("安全客数据为空,跳过执行。")
|
||||
|
||||
# 华为数据获取分发
|
||||
huawei_main()
|
||||
|
||||
# 奇安信数据获取分发
|
||||
qianxin_main()
|
||||
qianxin_results = Src_qianxin(time_1)
|
||||
if qianxin_results != False:
|
||||
result_qianxin_long, result_qianxin_short = qianxin_results
|
||||
check_avaliable(result_qianxin_long, result_qianxin_short, "奇安信攻防社区资讯")
|
||||
else:
|
||||
logger.info("奇安信数据为空,跳过执行。")
|
||||
|
||||
# FreeBuf数据获取分发
|
||||
freebuf_main()
|
||||
freebuf_results = Src_freebuf(time_1)
|
||||
if freebuf_results != False:
|
||||
result_freebuf_long, result_freebuf_short = freebuf_results
|
||||
check_avaliable(result_freebuf_long, result_freebuf_short, "FreeBuf资讯")
|
||||
else:
|
||||
logger.info("FreeBuf数据为空,跳过执行。")
|
||||
|
||||
# 先知数据获取分发
|
||||
xianzhi_main()
|
||||
xianzhi_results = Src_xianzhi(time_1)
|
||||
if xianzhi_results != False:
|
||||
result_xianzhi_long, result_xianzhi_short = xianzhi_results
|
||||
check_avaliable(result_xianzhi_long, result_xianzhi_short, "先知社区资讯")
|
||||
else:
|
||||
logger.info("先知数据为空,跳过执行。")
|
||||
|
||||
# 4hou数据获取分发
|
||||
M_4hou_main()
|
||||
M_4hou_results = Src_4hou(time_1)
|
||||
if M_4hou_results != False:
|
||||
result_4hou_long, result_4hou_short = M_4hou_results
|
||||
check_avaliable(result_4hou_long, result_4hou_short, "嘶吼资讯")
|
||||
else:
|
||||
logger.info("嘶吼数据为空,跳过执行。")
|
||||
|
||||
# 洞见微信安全数据获取分发
|
||||
doonsec_main()
|
||||
doonsec_results = Src_doonsec(False, Doonsec_switch, Doonsec)
|
||||
if doonsec_results != False:
|
||||
result_doonsec_long, result_doonsec_short = doonsec_results
|
||||
check_avaliable(result_doonsec_long, result_doonsec_short, "洞见微信安全资讯")
|
||||
else:
|
||||
logger.info("洞见微信安全数据为空,跳过执行。")
|
||||
|
||||
def send_job_SX():
|
||||
Sogou_WX = get_kewords_config('Sogou-WX')
|
||||
sougou_wx_main(Sogou_WX)
|
||||
result_sx_long = Src_sougou_wx(False)
|
||||
result_sx_short = Src_sougou_wx(True)
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
check_avaliable(result_sx_long, result_sx_short, "微信公众号关键词相关内容", webhook_url, timestamp, sign)
|
||||
result_sx_long, result_sx_short = Src_sougou_wx()
|
||||
check_avaliable(result_sx_long, result_sx_short, "微信公众号关键词相关内容")
|
||||
|
||||
def send_job_github(time_1):
|
||||
keyword_list, tool_list, user_list, black_words = load_github_config()
|
||||
github_main(keyword_list, tool_list, user_list, black_words)
|
||||
result_github_1_long, result_github_2_long, result_github_3_long, result_github_4_long = Src_github(time_1, False)
|
||||
result_github_1_short, result_github_2_short, result_github_3_short, result_github_4_short = Src_github(time_1, True)
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
check_avaliable(result_github_1_long, result_github_1_short, "Github项目监控-关键词监控", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_github_2_long, result_github_2_short, "Github项目监控-项目更新情况", webhook_url, timestamp, sign)
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
check_avaliable(result_github_3_long, result_github_3_short, "Github项目监控-大佬工具", webhook_url, timestamp, sign)
|
||||
check_avaliable(result_github_4_long, result_github_4_short, "Github项目监控-项目版本发布监测", webhook_url, timestamp, sign)
|
||||
results = Src_github(time_1)
|
||||
|
||||
# 解构返回的结果
|
||||
result_github_1_long, result_github_1_short = results[0]
|
||||
result_github_2_long, result_github_2_short = results[1]
|
||||
result_github_3_long, result_github_3_short = results[2]
|
||||
result_github_4_long, result_github_4_short = results[3]
|
||||
|
||||
# 检查并处理结果
|
||||
check_avaliable(result_github_1_long, result_github_1_short, "Github项目监控-关键词监控")
|
||||
check_avaliable(result_github_2_long, result_github_2_short, "Github项目监控-项目更新情况")
|
||||
check_avaliable(result_github_3_long, result_github_3_short, "Github项目监控-大佬工具")
|
||||
check_avaliable(result_github_4_long, result_github_4_short, "Github项目监控-项目版本发布监测")
|
||||
|
||||
def send_job_baidu():
|
||||
Baidu = get_kewords_config('Baidu')
|
||||
baidu_main(Baidu)
|
||||
result_baidu_long = Src_baidu(False)
|
||||
result_baidu_short = Src_baidu(True)
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
check_avaliable(result_baidu_long, result_baidu_short, "百度搜索关键词相关内容", webhook_url, timestamp, sign)
|
||||
result_baidu_long, result_baidu_short = Src_baidu()
|
||||
check_avaliable(result_baidu_long, result_baidu_short, "百度搜索关键词相关内容")
|
||||
|
||||
# 探测rss源状态
|
||||
def check_rss_status(url):
|
||||
|
132
Dev_test.py
132
Dev_test.py
@ -0,0 +1,132 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Author: MasonLiu
|
||||
@Description: 本程序可以爬取各安全资讯源,并发送到飞书群组。
|
||||
"""
|
||||
|
||||
import schedule
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import yaml
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from SendCore.FeishuSendBot import SendToFeishu, gen_sign
|
||||
from SendCore.QiweiSendBot import SendToWX
|
||||
from spider.common import run, seebug_main, M_4hou_main, anquanke_main, sec_wiki_main, huawei_main, doonsec_main, qianxin_main
|
||||
from spider.freebuf import freebuf_main
|
||||
from spider.xianzhi import xianzhi_main
|
||||
from spider.sougou_wx import sougou_wx_main
|
||||
from spider.github import github_main, load_github_config
|
||||
from spider.baidu import baidu_main
|
||||
from GotoSend.M_4hou import Src_4hou
|
||||
from GotoSend.anquanke import Src_anquanke
|
||||
from GotoSend.doonsec import Src_doonsec
|
||||
from GotoSend.xianzhi import Src_xianzhi
|
||||
from GotoSend.freebuf import Src_freebuf
|
||||
from GotoSend.qianxin import Src_qianxin
|
||||
from GotoSend.seebug import Src_seebug
|
||||
from GotoSend.sougou_wx import Src_sougou_wx
|
||||
from GotoSend.github import Src_github
|
||||
from GotoSend.baidu import Src_baidu
|
||||
from config.check_config import get_core_config, get_debug_config, get_kewords_config
|
||||
from loguru import logger
|
||||
|
||||
# 清除所有已有的日志记录器配置
|
||||
logger.remove()
|
||||
|
||||
logger.add("./resources/log/core.log",
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} - {level} - {name}:{function}:{line} - {message}",
|
||||
rotation="100 MB",
|
||||
compression="zip",
|
||||
encoding="utf-8")
|
||||
# shell终端打印日志
|
||||
debug = get_debug_config()
|
||||
if debug == "True":
|
||||
logger.add(lambda msg: print(msg),
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} - {level} - {name}:{function}:{line} - {message}")
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logger.info("接收到退出信号,程序即将退出...")
|
||||
sys.exit(0)
|
||||
|
||||
# 全局变量
|
||||
signal.signal(signal.SIGINT, signal_handler) # Ctrl+C
|
||||
signal.signal(signal.SIGTERM, signal_handler) # kill命令
|
||||
webhook_url_once, timestamp_once, sign_once = gen_sign()
|
||||
e_hour, time_choice, choice, fs_activate, wx_activate, ding_activate, lx_activate, url_web = get_core_config()
|
||||
|
||||
|
||||
def check_avaliable(info_long, info_short, title):
|
||||
if info_short: # 发送精简文章相关内容
|
||||
# 企业微信相关
|
||||
if wx_activate == "True":
|
||||
# logger.info(f"{title} 递送中(企业微信):")
|
||||
print("正在发送精简文章内容...")
|
||||
for info in info_short:
|
||||
result = SendToWX(info, title)
|
||||
print(result)
|
||||
logger.info(result)
|
||||
time.sleep(15)
|
||||
else:
|
||||
print("精简文章内容为空,跳过执行。")
|
||||
pass
|
||||
|
||||
if info_long: # 发送完整文章相关内容
|
||||
if fs_activate == "True":
|
||||
# logger.info(f"{title} 递送中(飞书):")
|
||||
webhook_url, timestamp, sign = gen_sign()
|
||||
result = SendToFeishu(info_long, title, webhook_url, timestamp, sign)
|
||||
logger.info(result)
|
||||
time.sleep(15)
|
||||
else:
|
||||
pass
|
||||
|
||||
if not info_long and not info_short:
|
||||
logger.info(f"{title}数据为空,跳过执行。")
|
||||
|
||||
def send_job_RSS(time_1):
|
||||
Doonsec_switch, Doonsec = get_kewords_config('Doonsec')
|
||||
results = Src_doonsec(Doonsec_switch, Doonsec)
|
||||
if results != False:
|
||||
result_doonsec_long, result_doonsec_short = results
|
||||
check_avaliable(result_doonsec_long, result_doonsec_short, "洞见微信安全资讯")
|
||||
|
||||
|
||||
def main_job(e_hour):
|
||||
logger.info(f"发送程序启动,当前时间为:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
logger.info("正在启动各爬虫并获取资源中...")
|
||||
if 0 in choice:
|
||||
send_job_RSS(e_hour)
|
||||
logger.info("单次运行结束,等待下一次运行...")
|
||||
|
||||
def main_loop(time_choice):
|
||||
if time_choice == 1:
|
||||
while True:
|
||||
try:
|
||||
# 执行任务
|
||||
main_job(e_hour)
|
||||
time.sleep(e_hour * 60 * 60 - 3 * 60)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"发生错误: {e}, 程序已暂停")
|
||||
# result = SendToFeishu(f"发生错误: {e}, 程序已退出", "报错信息")
|
||||
exit()
|
||||
|
||||
elif time_choice == 0:
|
||||
# 设置每天的特定时间点执行job函数
|
||||
schedule.every().day.at("09:00").do(main_job, 12)
|
||||
schedule.every().day.at("12:00").do(main_job, 3)
|
||||
schedule.every().day.at("15:00").do(main_job, 3)
|
||||
schedule.every().day.at("18:00").do(main_job, 3)
|
||||
schedule.every().day.at("21:00").do(main_job, 3)
|
||||
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(60) # 每分钟检查一次是否有任务需要执行
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger.info("程序正在运行当中。")
|
||||
|
||||
main_loop(time_choice)
|
@ -107,28 +107,45 @@ def record_md(result, filename="./resources/history/sec_news.md"):
|
||||
# 写回文件
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n作者:{entry[5]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"链接:{entry[2]}\n上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n作者:{entry[5]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
f"链接:{entry[2]}\n上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**作者**:{entry[5]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_4hou(e_hour, Is_short):
|
||||
def Src_4hou(e_hour):
|
||||
if not os.path.exists('./resources/db/4hou.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -147,17 +164,27 @@ def Src_4hou(e_hour, Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return ""
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_4hou(4, False)
|
||||
if reslts != "":
|
||||
print(reslts)
|
||||
results = Src_4hou(4)
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
print("嘶吼数据为空,跳过执行。")
|
||||
|
||||
print("嘶吼数据为空,跳过执行。")
|
Binary file not shown.
Binary file not shown.
@ -102,29 +102,46 @@ def record_md(result, filename="./resources/history/sec_news.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n作者:{entry[6]}\n来源:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[5]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif Is_short == True:
|
||||
result += f"文章:{entry[1]}\n"
|
||||
result += f"链接:{entry[2]}\n上传时间:{entry[5]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n作者:{entry[6]}\n来源:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[5]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:{entry[1]}\n"
|
||||
f"链接:{entry[2]}\n上传时间:{entry[5]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**作者**:{entry[6]}\n"
|
||||
record += f"**来源**:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[5]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_anquanke(e_hour, Is_short):
|
||||
def Src_anquanke(e_hour):
|
||||
if not os.path.exists('./resources/db/anquanke.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -143,16 +160,27 @@ def Src_anquanke(e_hour, Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_anquanke(4, False)
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_anquanke(4)
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
print("安全客数据为空,跳过执行。")
|
||||
print("安全客数据为空,跳过执行。")
|
@ -137,30 +137,48 @@ def record_md(result, filename="./resources/history/baidu_news.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
result += f"发布时间:{entry[4]}\n"
|
||||
result += f"来源:{entry[5]}\n"
|
||||
result += f"关键词:{entry[6]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
result_long += f"发布时间:{entry[4]}\n"
|
||||
result_long += f"来源:{entry[5]}\n"
|
||||
result_long += f"关键词:{entry[6]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += f"**来源**:{entry[5]}\n"
|
||||
record += f"**关键词**:{entry[6]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
def Src_baidu(Is_short):
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_baidu():
|
||||
if not os.path.exists('./resources/db/baidu.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -179,16 +197,27 @@ def Src_baidu(Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_baidu(False)
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_baidu()
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
print("微信公众号数据为空,跳过执行。")
|
||||
print("百度数据为空,跳过执行。")
|
||||
|
@ -147,31 +147,49 @@ def record_md(result, filename="./resources/history/tech_passage.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"作者:{entry[5]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += f"简介:{entry[3]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result_long += f"作者:{entry[5]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += f"简介:{entry[3]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**作者**:{entry[5]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += f"**简介**:{entry[3]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
|
||||
def Src_doonsec(Is_short, Doonsec_switch, Doonsec):
|
||||
def Src_doonsec(Doonsec_switch, Doonsec):
|
||||
if not os.path.exists('./resources/db/doonsec.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -180,25 +198,36 @@ def Src_doonsec(Is_short, Doonsec_switch, Doonsec):
|
||||
# clear_table()
|
||||
|
||||
# 获取 JSON 数据
|
||||
M_doonsec_data = get_doonsec_json()
|
||||
doonsec_data = get_doonsec_json()
|
||||
|
||||
# 插入数据到数据库
|
||||
insert_data(M_doonsec_data)
|
||||
insert_data(doonsec_data)
|
||||
|
||||
# 查询指定时间段内的数据
|
||||
filtered_articles = select_articles(Doonsec_switch, Doonsec)
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_doonsec(False, False, ["webshell", "2000", "POC", "SQL", "XSS", "CSRF", "漏洞"] )
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_doonsec(False, ["webshell", "2000", "POC", "SQL", "XSS", "CSRF", "漏洞"])
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 写入长文本结果
|
||||
with open("./1.txt", "a", encoding="utf-8") as f:
|
||||
f.write(result_long)
|
||||
f.write("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 写入分块的短文本结果
|
||||
for short_result in short_results:
|
||||
with open("./2.txt", "a", encoding="utf-8") as f:
|
||||
f.write(short_result)
|
||||
f.write("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
|
@ -108,28 +108,45 @@ def record_md(result, filename="./resources/history/sec_news.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n类型:{entry[5]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n类型:{entry[5]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**类型**:{entry[5]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_freebuf(e_hour, Is_short):
|
||||
def Src_freebuf(e_hour):
|
||||
if not os.path.exists('./resources/db/freebuf.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -148,15 +165,26 @@ def Src_freebuf(e_hour, Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_freebuf(4, False)
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_freebuf(24)
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
|
@ -297,59 +297,81 @@ def record_md(result, filename="./resources/history/github.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short, choice):
|
||||
result = ""
|
||||
def get_filtered_articles(entries, choice):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
if choice == 1:
|
||||
result += f"关键词【{entry[6]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"项目描述:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += f"开发语言:{entry[7]}\t\t作者:{entry[5]}\n"
|
||||
result += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 2:
|
||||
result += f"项目:[{entry[1]}]({entry[2]})存在更新!!!\n"
|
||||
result += f"更新描述:{entry[3]}\n"
|
||||
result += f"更新时间:{entry[4]}\n"
|
||||
result += f"提交者:{entry[5]},[点此查看提交详情]({entry[7]})\n"
|
||||
result += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 3:
|
||||
result += f"大佬 {entry[5]} 上传了一个新工具:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"项目描述:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 4:
|
||||
result += f"【{entry[3]}】为[{entry[4]}]({entry[1]})发布了新版本,请及时查收!\n"
|
||||
result += f"发布时间:{entry[2]}\n"
|
||||
result += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif Is_short == True:
|
||||
if choice == 1:
|
||||
result += f"关键词【{entry[7]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += f"开发语言:{entry[6]}\t\t作者:{entry[5]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 2:
|
||||
result += f"项目:[{entry[1]}]({entry[2]})存在更新!!!\n"
|
||||
result += f"更新描述:{entry[3]}\n"
|
||||
result += f"更新时间:{entry[4]}\n"
|
||||
result += f"提交者:{entry[5]},[点此查看提交详情]({entry[7]})\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 3:
|
||||
result += f"大佬 {entry[5]} 上传了一个新工具:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"项目描述:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 4:
|
||||
result += f"【{entry[3]}】为[{entry[4]}]({entry[1]})发布了新版本,请及时查收!\n"
|
||||
result += f"发布时间:{entry[2]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
if choice == 1:
|
||||
# 构建长文本结果
|
||||
result_long += f"关键词【{entry[6]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
result_long += f"项目描述:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += f"开发语言:{entry[7]}\t\t作者:{entry[5]}\n"
|
||||
result_long += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"关键词【{entry[6]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
f"开发语言:{entry[7]}\t\t作者:{entry[5]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
elif choice == 2:
|
||||
# 构建长文本结果
|
||||
result_long += f"项目:[{entry[1]}]({entry[2]})存在更新!!!\n"
|
||||
result_long += f"更新描述:{entry[3]}\n"
|
||||
result_long += f"更新时间:{entry[4]}\n"
|
||||
result_long += f"提交者:{entry[5]},[点此查看提交详情]({entry[7]})\n"
|
||||
result_long += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"项目:[{entry[1]}]({entry[2]})存在更新!!!\n"
|
||||
f"更新时间:{entry[4]}\n"
|
||||
f"提交者:{entry[5]},[点此查看提交详情]({entry[7]})\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
elif choice == 3:
|
||||
# 构建长文本结果
|
||||
result_long += f"大佬 {entry[5]} 上传了一个新工具:[{entry[1]}]({entry[2]})\n"
|
||||
result_long += f"项目描述:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"大佬 {entry[5]} 上传了一个新工具:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
elif choice == 4:
|
||||
# 构建长文本结果
|
||||
result_long += f"【{entry[3]}】为[{entry[4]}]({entry[1]})发布了新版本,请及时查收!\n"
|
||||
result_long += f"发布时间:{entry[2]}\n"
|
||||
result_long += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"【{entry[3]}】为[{entry[4]}]({entry[1]})发布了新版本,请及时查收!\n"
|
||||
f"发布时间:{entry[2]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
if choice == 1:
|
||||
record += f"#### 关键词【{entry[7]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"#### 关键词【{entry[6]}】发现新项目:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**项目描述**:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += f"**开发语言**:{entry[6]}\n**作者**:{entry[5]}\n"
|
||||
record += f"**开发语言**:{entry[7]}\n**作者**:{entry[5]}\n"
|
||||
record += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
elif choice == 2:
|
||||
record += f"#### 项目:[{entry[1]}]({entry[2]})存在更新!!!\n"
|
||||
@ -367,11 +389,15 @@ def get_filtered_articles(entries, Is_short, choice):
|
||||
record += f"**发布时间**:{entry[2]}\n"
|
||||
record += "\n" + "-" * 10 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_github(e_hour, Is_short):
|
||||
def Src_github(e_hour):
|
||||
if not os.path.exists('./resources/db/github.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -385,35 +411,48 @@ def Src_github(e_hour, Is_short):
|
||||
# 查询指定时间段内的数据
|
||||
keyword_data, repo_data, user_data, release_data = select_articles(e_hour)
|
||||
|
||||
results = []
|
||||
if keyword_data:
|
||||
result_1 = get_filtered_articles(keyword_data, Is_short, 1)
|
||||
result_long_1, short_results_1 = get_filtered_articles(keyword_data, 1)
|
||||
results.append((result_long_1, short_results_1))
|
||||
else:
|
||||
result_1 = ""
|
||||
results.append(("", []))
|
||||
|
||||
if repo_data:
|
||||
result_2 = get_filtered_articles(repo_data, Is_short, 2)
|
||||
result_long_2, short_results_2 = get_filtered_articles(repo_data, 2)
|
||||
results.append((result_long_2, short_results_2))
|
||||
else:
|
||||
result_2 = ""
|
||||
results.append(("", []))
|
||||
|
||||
if user_data:
|
||||
result_3 = get_filtered_articles(user_data, Is_short, 3)
|
||||
result_long_3, short_results_3 = get_filtered_articles(user_data, 3)
|
||||
results.append((result_long_3, short_results_3))
|
||||
else:
|
||||
result_3 = ""
|
||||
results.append(("", []))
|
||||
|
||||
if release_data:
|
||||
result_4 = get_filtered_articles(release_data, Is_short, 4)
|
||||
result_long_4, short_results_4 = get_filtered_articles(release_data, 4)
|
||||
results.append((result_long_4, short_results_4))
|
||||
else:
|
||||
result_4 = ""
|
||||
return result_1, result_2, result_3, result_4
|
||||
results.append(("", []))
|
||||
|
||||
return results
|
||||
|
||||
if __name__ == "__main__":
|
||||
result_1, result_2, result_3, result_4 = Src_github(240, False)
|
||||
if result_1 != "":
|
||||
print(result_1)
|
||||
if result_2 != "":
|
||||
print(result_2)
|
||||
if result_3 != "":
|
||||
print(result_3)
|
||||
if result_4 != "":
|
||||
print(result_4)
|
||||
if result_1 == "" and result_2 == "" and result_3 == "" and result_4 == "":
|
||||
results = Src_github(240)
|
||||
for i, (result_long, short_results) in enumerate(results, start=1):
|
||||
if result_long != "":
|
||||
print(f"长文本结果 {i}:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 10 + "\n")
|
||||
|
||||
if short_results:
|
||||
print(f"分块的短文本结果 {i}:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 10 + "\n")
|
||||
|
||||
if all(result_long == "" and not short_results for result_long, short_results in results):
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 10)
|
||||
print("github数据为空,跳过执行。")
|
||||
print("github数据为空,跳过执行。")
|
||||
|
@ -99,30 +99,47 @@ def record_md(result, filename="./resources/history/tech_passage.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n来源:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[5]}\n"
|
||||
result += f"描述:{entry[4]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
result += f"上传时间:{entry[5]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n来源:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[5]}\n"
|
||||
result_long += f"描述:{entry[4]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[5]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**来源**:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[5]}\n"
|
||||
record += f"**描述**:{entry[4]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_qianxin(e_hour, Is_short):
|
||||
def Src_qianxin(e_hour):
|
||||
if not os.path.exists('./resources/db/qianxin.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -141,16 +158,27 @@ def Src_qianxin(e_hour, Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_qianxin(4, False)
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_qianxin(4)
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
print("奇安信攻防社区数据为空,跳过执行。")
|
||||
print("奇安信攻防社区数据为空,跳过执行。")
|
@ -106,30 +106,47 @@ def record_md(result, filename="./resources/history/sec_news.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n类型:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[5]}\n"
|
||||
result += f"{entry[4]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})"
|
||||
result += f"上传时间:{entry[5]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n类型:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[5]}\n"
|
||||
result_long += f"{entry[4]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})\n"
|
||||
f"上传时间:{entry[5]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n"
|
||||
record += f"**类型**:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[5]}\n"
|
||||
record += f"{entry[4]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 处理最后一个结果
|
||||
if result_short:
|
||||
short_results.append(result_short)
|
||||
|
||||
record_md(record)
|
||||
return result
|
||||
|
||||
return result_long, short_results
|
||||
|
||||
def Src_seebug(e_hour, Is_short):
|
||||
def Src_seebug(e_hour):
|
||||
if not os.path.exists('./resources/db/seebug.db'):
|
||||
# 创建数据库和表
|
||||
create_database()
|
||||
@ -148,16 +165,27 @@ def Src_seebug(e_hour, Is_short):
|
||||
# print(filtered_articles)
|
||||
|
||||
if filtered_articles:
|
||||
results = get_filtered_articles(filtered_articles, Is_short)
|
||||
return results
|
||||
result_long, short_results = get_filtered_articles(filtered_articles)
|
||||
return result_long, short_results
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
reslts = Src_seebug(100, False)
|
||||
if reslts != False:
|
||||
print(reslts)
|
||||
results = Src_seebug(100)
|
||||
if results != False:
|
||||
result_long, short_results = results
|
||||
|
||||
# 打印长文本结果
|
||||
print("长文本结果:")
|
||||
print(result_long)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
|
||||
# 打印分块的短文本结果
|
||||
print("分块的短文本结果:")
|
||||
for short_result in short_results:
|
||||
print(short_result)
|
||||
print("\n" + "-" * 40 + "\n")
|
||||
else:
|
||||
# 如果为空,则跳过执行
|
||||
print("-" * 40)
|
||||
print("Seebug社区数据为空,跳过执行。")
|
||||
print("Seebug社区数据为空,跳过执行。")
|
@ -139,30 +139,48 @@ def record_md(result, filename="./resources/history/wx_news.md"):
|
||||
with open(filename, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
def get_filtered_articles(entries, Is_short):
|
||||
result = ""
|
||||
def get_filtered_articles(entries):
|
||||
result_long = ""
|
||||
result_short = ""
|
||||
record = ""
|
||||
short_results = []
|
||||
|
||||
for entry in entries:
|
||||
if Is_short == False:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += f"作者:{entry[5]}\n"
|
||||
result += f"关键词:{entry[6]}\n"
|
||||
result += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
if Is_short == True:
|
||||
result += f"文章:[{entry[1]}]({entry[2]})"
|
||||
result += f"上传时间:{entry[4]}\n"
|
||||
result += "\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
# 构建长文本结果
|
||||
result_long += f"文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
result_long += f"上传时间:{entry[4]}\n"
|
||||
result_long += f"作者:{entry[5]}\n"
|
||||
result_long += f"关键词:{entry[6]}\n"
|
||||
result_long += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||
|
||||
# 构建短文本结果并进行分块处理
|
||||
current_entry = (
|
||||
f"文章:[{entry[1]}]({entry[2]})"
|
||||
f"上传时间:{entry[4]}\n"
|
||||
"\n" + "-" * 3 + "\n" # 添加分隔线以便区分不同文章
|
||||
)
|
||||
temp_result = result_short + current_entry
|
||||
if len(temp_result.encode('utf-8')) > 4096:
|
||||
short_results.append(result_short)
|
||||
result_short = current_entry
|
||||
else:
|
||||
result_short = temp_result
|
||||
|
||||
record += f"#### 文章:[{entry[1]}]({entry[2]})\n描述:{entry[3]}\n"
|
||||
record += f"**上传时间**:{entry[4]}\n"
|
||||
record += f"**作者**:{entry[5]}\n"
|
||||
record += f"**关键词**:{entry[6]}\n"
|
||||
record += "\n" + "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||