diff --git a/Core.py b/Core.py index c00bca8..5078280 100644 --- a/Core.py +++ b/Core.py @@ -14,6 +14,7 @@ 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 # 加载参数 with open('./config.yaml', 'r', encoding="utf-8") as file: @@ -36,6 +37,7 @@ def send_job(time_1): reslt_xianzhi = Src_xianzhi(time_1) reslt_freebuf = Src_freebuf(time_1) reslt_qianxin = Src_qianxin(time_1) + reslt_seebug = Src_seebug(time_1) webhook_url, timestamp, sign = gen_sign() @@ -106,6 +108,18 @@ def send_job(time_1): print("-" * 40) print("奇安信攻防社区数据为空,跳过执行。") + # 发送Seebug资讯 + if reslt_seebug: + reslt_seebug = Src_seebug(1000) + webhook_url, timestamp, sign = gen_sign() + print("-" * 40) + print("Seebug社区资讯递送中:") + SendToFeishu(reslt_seebug, "Seebug社区资讯递送", webhook_url, timestamp, sign) + print("-" * 40 + "\n") + else: + print("-" * 40) + print("Seebug社区数据为空,跳过执行。") + def signal_handler(sig, frame): print("接收到退出信号,程序即将退出...") sys.exit(0) @@ -150,7 +164,7 @@ def test_rss_source(): # "安全维基": "https://www.sec_wiki.com/news/rss", "安全客": "https://api.anquanke.com/data/v1/rss", "嘶吼": "https://www.4hou.com/feed", - # "Seebug社区": "https://paper.seebug.org/rss/", + "Seebug社区": "https://paper.seebug.org/rss/", "FreeBuf社区": "https://www.freebuf.com/feed", "先知社区": "https://xz.aliyun.com/feed" } diff --git a/GotoSend_seebug.py b/GotoSend_seebug.py new file mode 100644 index 0000000..2551f93 --- /dev/null +++ b/GotoSend_seebug.py @@ -0,0 +1,134 @@ +import json +import sqlite3 +import os +from datetime import datetime, timedelta +from SendBot import SendToFeishu +import email.utils + + +def create_database(): + conn = sqlite3.connect('./db/seebug.db') + cursor = conn.cursor() + cursor.execute('''CREATE TABLE IF NOT EXISTS articles ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT, + link TEXT, + category TEXT, + description TEXT, + pubDate DATETIME + )''') + conn.commit() + conn.close() + + +def insert_data(data): + conn = sqlite3.connect('./db/seebug.db') + cursor = conn.cursor() + for entry in data: + # 解析并格式化时间 + parsed_date = email.utils.parsedate_to_datetime(entry['pubDate']) + formatted_date = parsed_date.strftime('%Y-%m-%d %H:%M:%S') + + cursor.execute(''' + INSERT INTO articles (title, link, category, description, pubDate) + VALUES (?, ?, ?, ?, ?) + ''', (entry['title'], entry['link'], entry['category'], entry['description'], formatted_date)) + conn.commit() + conn.close() + +def get_seebug_json(): + # 检查文件是否存在 + if not os.path.exists('./JSON/seebug.json'): + raise FileNotFoundError(f"seebug.json文件不存在,请检查程序是否运行正常!") + + # 打开并读取JSON文件 + with open('./JSON/seebug.json', 'r', encoding='utf-8') as file: + data = json.load(file) + + # 假设data是一个包含多个JSON对象的列表 + if not isinstance(data, list): + raise ValueError("JSON文件格式错误,请检查common.py是否异常!") + + # 提取所需字段并编号 + total_data = [] + for index, item in enumerate(data, start=1): + entry = { + "id": index, + "title": item.get("title", ""), + "link": item.get("link", ""), + "description": item.get("description", ""), + "pubDate": item.get("pubDate", ""), + "category": item.get("category", "") + } + total_data.append(entry) + + return total_data + +def select_articles(e_hour): + conn = sqlite3.connect('./db/seebug.db') + cursor = conn.cursor() + + # 获取当前日期和时间 + now = datetime.now() + start_time = now - timedelta(hours=e_hour) + end_time = now + + # 查询指定时间段内的数据 + cursor.execute(''' + SELECT * FROM articles + WHERE pubDate BETWEEN ? AND ? + ''', (start_time.strftime('%Y-%m-%d %H:%M:%S'), end_time.strftime('%Y-%m-%d %H:%M:%S'))) + + results = cursor.fetchall() + conn.close() + return results + +def clear_table(): + conn = sqlite3.connect('./db/seebug.db') + cursor = conn.cursor() + cursor.execute('DELETE FROM articles') + conn.commit() + conn.close() + +def get_filtered_articles(entries): + result = "" + for entry in entries: + result += f"类型:{entry[3]}\t文章:{entry[1]}" + result += f"链接:{entry[2]}\t上传时间:{entry[5]}\n" + result += f"{entry[4]}\n" + result += "-" * 40 + "\n" # 添加分隔线以便区分不同文章 + return result + + +def Src_seebug(e_hour): + if not os.path.exists('./db/seebug.db'): + # 创建数据库和表 + create_database() + + # 清空表 + clear_table() + + # 获取 JSON 数据 + M_seebug_data = get_seebug_json() + + # 插入数据到数据库 + insert_data(M_seebug_data) + + # 查询指定时间段内的数据 + filtered_articles = select_articles(e_hour) + # print(filtered_articles) + + if filtered_articles: + results = get_filtered_articles(filtered_articles) + return results + else: + return False + +if __name__ == "__main__": + reslts = Src_seebug(100) + if reslts != False: + print(reslts) + else: + # 如果为空,则跳过执行 + print("-" * 40) + print("Seebug社区数据为空,跳过执行。") diff --git a/README.md b/README.md index dd8b20b..6384510 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,15 @@ RSS订阅链接来源:https://github.com/zhengjim/Chinese-Security-RSS
使用python-json进行格式化,然后使用飞书webhook机器人进行发送
config.yaml可指定大部分可能需要的参数
+### 使用建议:
+Linux系统建议下载screen于后台持续运行本脚本。
+debian/ubuntu/kali: `apt install screen`
+centos: `yum install screen`
+创建新会话:`screen -S 会话名称`
+保存并退回到界面:`ctrl+a+d`
+重新进入会话:`screen -r 会话名称`
+结束对话:进入会话后输入`exit`
+ ### 使用方法:
先下载支持库:`pip install -r requirements.txt`
随后便可直接运行:`python Core.py`
diff --git a/__pycache__/GotoSend_seebug.cpython-312.pyc b/__pycache__/GotoSend_seebug.cpython-312.pyc new file mode 100644 index 0000000..4226ff8 Binary files /dev/null and b/__pycache__/GotoSend_seebug.cpython-312.pyc differ diff --git a/db/seebug.db b/db/seebug.db new file mode 100644 index 0000000..512e3c4 Binary files /dev/null and b/db/seebug.db differ diff --git a/test.py b/test.py new file mode 100644 index 0000000..cce6dcc --- /dev/null +++ b/test.py @@ -0,0 +1,9 @@ +from SendBot import SendToFeishu, gen_sign +from GotoSend_seebug import Src_seebug + +reslt_seebug = Src_seebug(1000) +webhook_url, timestamp, sign = gen_sign() +print("-" * 40) +print("Seebug社区资讯递送中:") +SendToFeishu(reslt_seebug, "Seebug社区资讯递送", webhook_url, timestamp, sign) +print("-" * 40 + "\n") \ No newline at end of file