update
This commit is contained in:
parent
b636eb32f1
commit
b2305c8473
11
Core.py
11
Core.py
@ -2,12 +2,11 @@ import signal
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from SendBot import SendToFeishu, gen_sign
|
from SendBot import SendToFeishu
|
||||||
from media.common import run
|
from media.common import run
|
||||||
from media.freebuf import freebuf_main
|
from media.freebuf import freebuf_main
|
||||||
from media.xianzhi import xianzhi_main
|
from media.xianzhi import xianzhi_main
|
||||||
|
|
||||||
webhook_url, timestamp, sign = gen_sign()
|
|
||||||
|
|
||||||
def crab_job():
|
def crab_job():
|
||||||
print("正在启动各爬虫并获取资源中...")
|
print("正在启动各爬虫并获取资源中...")
|
||||||
@ -29,17 +28,15 @@ def main_loop():
|
|||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
# 检查是否为特定时间点
|
# 检查是否为特定时间点
|
||||||
if now.hour == 17 and now.minute == 25:
|
if now.hour == 11 and now.minute == 5:
|
||||||
crab_job()
|
crab_job()
|
||||||
print("执行完毕,等待下一次执行...")
|
print("执行完毕,等待下一次执行...")
|
||||||
else:
|
else:
|
||||||
print("正在等待执行...")
|
print("正在等待执行...")
|
||||||
time.sleep(35) # 每隔35秒执行一次
|
time.sleep(35) # 每隔35秒执行一次
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"发生错误: {e}")
|
print(f"发生错误: {e} ,程序已暂停")
|
||||||
msg = {"msg_type":"text","timestamp": f"{timestamp}","sign": f"{sign}","content":{"text":f"发生错误: {e} ,程序已暂停"}}
|
SendToFeishu(f"发生错误: {e} ,程序已退出", "报错信息")
|
||||||
print(msg)
|
|
||||||
# SendToFeishu(msg)
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
136
GotoSend_4hou.py
Normal file
136
GotoSend_4hou.py
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from SendBot import SendToFeishu
|
||||||
|
|
||||||
|
def create_database():
|
||||||
|
conn = sqlite3.connect('./db/4hou.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS articles (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT,
|
||||||
|
link TEXT,
|
||||||
|
description TEXT,
|
||||||
|
pubDate DATETIME,
|
||||||
|
author TEXT
|
||||||
|
)''')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def insert_data(data):
|
||||||
|
conn = sqlite3.connect('./db/4hou.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
for entry in data:
|
||||||
|
try:
|
||||||
|
# 解析 pubDate 字符串为 datetime 对象
|
||||||
|
pub_date = datetime.strptime(entry['pubDate'], '%a, %d %b %Y %H:%M:%S %z')
|
||||||
|
# 格式化 pubDate 为所需的格式
|
||||||
|
formatted_pub_date = pub_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
except ValueError:
|
||||||
|
# 如果解析失败,使用原始 pubDate 字符串
|
||||||
|
formatted_pub_date = entry['pubDate']
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT INTO articles (title, link, description, pubDate, author)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
''', (entry['title'], entry['link'], entry['description'], formatted_pub_date, entry['author']))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def get_4hou_json():
|
||||||
|
# 检查文件是否存在
|
||||||
|
if not os.path.exists('./JSON/4hou.json'):
|
||||||
|
raise FileNotFoundError(f"4hou.json文件不存在,请检查程序是否运行正常!")
|
||||||
|
|
||||||
|
# 打开并读取JSON文件
|
||||||
|
with open('./JSON/4hou.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", ""),
|
||||||
|
"author": item.get("author", "")
|
||||||
|
}
|
||||||
|
total_data.append(entry)
|
||||||
|
|
||||||
|
return total_data
|
||||||
|
|
||||||
|
def query_articles_within_time_range():
|
||||||
|
conn = sqlite3.connect('./db/4hou.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# 获取当前日期和时间
|
||||||
|
now = datetime.now()
|
||||||
|
# 计算前一天11点的时间
|
||||||
|
start_time = datetime(now.year, now.month, now.day, 11) - timedelta(days=1)
|
||||||
|
# print(start_time)
|
||||||
|
# 计算当日11点的时间
|
||||||
|
end_time = datetime(now.year, now.month, now.day, 11)
|
||||||
|
# print(end_time)
|
||||||
|
|
||||||
|
# 查询指定时间段内的数据
|
||||||
|
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/4hou.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[5]}\t文章:{entry[1]}\n"
|
||||||
|
result += f"链接:{entry[2]}\t上传时间:{entry[4]}\n"
|
||||||
|
result += "-" * 40 + "\n" # 添加分隔线以便区分不同文章
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def Src_4hou():
|
||||||
|
if not os.path.exists('./db/4hou.db'):
|
||||||
|
# 创建数据库和表
|
||||||
|
create_database()
|
||||||
|
|
||||||
|
# 清空表
|
||||||
|
clear_table()
|
||||||
|
|
||||||
|
# 获取 JSON 数据
|
||||||
|
M_4hou_data = get_4hou_json()
|
||||||
|
|
||||||
|
# 插入数据到数据库
|
||||||
|
insert_data(M_4hou_data)
|
||||||
|
|
||||||
|
# 查询指定时间段内的数据
|
||||||
|
filtered_articles = query_articles_within_time_range()
|
||||||
|
# print(filtered_articles)
|
||||||
|
|
||||||
|
if filtered_articles:
|
||||||
|
results = get_filtered_articles(filtered_articles)
|
||||||
|
SendToFeishu(results, "4hou资讯递送")
|
||||||
|
# print(results)
|
||||||
|
else:
|
||||||
|
# 如果为空,则跳过执行
|
||||||
|
print("4hou数据为空,跳过执行。")
|
||||||
|
# print(results)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
Src_4hou()
|
29
SendBot.py
29
SendBot.py
@ -36,7 +36,27 @@ def gen_sign():
|
|||||||
webhook_url, timestamp, sign = gen_sign()
|
webhook_url, timestamp, sign = gen_sign()
|
||||||
|
|
||||||
# 主函数
|
# 主函数
|
||||||
def SendToFeishu(msg):
|
def SendToFeishu(body, header):
|
||||||
|
msg = {
|
||||||
|
"timestamp": f"{timestamp}",
|
||||||
|
"sign": f"{sign}",
|
||||||
|
"msg_type": "interactive",
|
||||||
|
"card": {
|
||||||
|
"elements":
|
||||||
|
[{
|
||||||
|
"tag": "markdown",
|
||||||
|
"content": f"{body}"
|
||||||
|
}],
|
||||||
|
"header": {
|
||||||
|
"title": {
|
||||||
|
"content": f"{header}",
|
||||||
|
"tag": "plain_text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# WebHook请求头
|
# WebHook请求头
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -59,6 +79,10 @@ def SendToFeishu(msg):
|
|||||||
# print(sign)
|
# print(sign)
|
||||||
# print(response.content)
|
# print(response.content)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 测试用消息体
|
# 测试用消息体
|
||||||
test_msg = {
|
test_msg = {
|
||||||
"timestamp": f"{timestamp}",
|
"timestamp": f"{timestamp}",
|
||||||
@ -93,5 +117,6 @@ test_msg = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
SendToFeishu(test_msg)
|
SendToFeishu(test_msg, "测试消息")
|
||||||
|
Binary file not shown.
BIN
db/4hou.db
Normal file
BIN
db/4hou.db
Normal file
Binary file not shown.
@ -128,9 +128,9 @@ def qianxin_main():
|
|||||||
print("数据已保存到./JSON/qianxin.json!")
|
print("数据已保存到./JSON/qianxin.json!")
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
# seebug_main()
|
seebug_main()
|
||||||
# M_4hou_main()
|
M_4hou_main()
|
||||||
# anquanke_main()
|
anquanke_main()
|
||||||
# sec_wiki_main()
|
# sec_wiki_main()
|
||||||
huawei_main()
|
huawei_main()
|
||||||
doonsec_main()
|
doonsec_main()
|
||||||
|
Loading…
Reference in New Issue
Block a user