修复一个小bug

This commit is contained in:
MasonLiu committed 2025-01-05 18:29:06 +08:00
1 parent 58c3b37308
commit 50b3bacd4c
3 files changed
+172 -22

No files matched your search

+43 -22
View File
@@ -15,7 +15,8 @@ def create_database():
link TEXT,
description TEXT,
pubDate DATETIME,
author TEXT
author TEXT,
is_sended BOOLEAN
)''')
conn.commit()
conn.close()
@@ -34,9 +35,14 @@ def insert_data(data):
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']))
SELECT 1 FROM articles WHERE title = ? AND author = ?
''', (entry['title'], entry['author']))
if cursor.fetchone() is None:
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()
@@ -68,39 +74,54 @@ def get_doonsec_json():
return total_data
def select_articles(e_hour, Doonsec_switch, Doonsec):
def select_articles(Doonsec_switch, Doonsec):
conn = sqlite3.connect('./resources/db/doonsec.db')
cursor = conn.cursor()
# 获取当前日期和时间
now = datetime.now()
start_time = now - timedelta(hours=e_hour, minutes=3)
end_time = now
two_days_ago = now - timedelta(days=2)
if Doonsec_switch == False:
if Doonsec_switch == False:
# 查询指定时间段内的数据
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')))
WHERE is_sended IS NULL AND pubDate BETWEEN ? AND ?
ORDER BY pubDate DESC
''', (two_days_ago.strftime('%Y-%m-%d %H:%M:%S'), now.strftime('%Y-%m-%d %H:%M:%S')))
elif Doonsec_switch == True:
# 查询指定时间段内且title包含特定关键词的数据
placeholders = ', '.join(['?'] * len(Doonsec))
like_conditions = ' OR '.join([f"title LIKE ?"] * len(Doonsec))
# 完整的查询语句
query = f'''
SELECT * FROM articles
WHERE pubDate BETWEEN ? AND ?
AND (title LIKE ? OR title LIKE ? OR title LIKE ?)
WHERE is_sended IS NULL AND pubDate BETWEEN ? AND ?
AND ({like_conditions})
ORDER BY pubDate DESC
'''
# 构建参数列表
params = [start_time.strftime('%Y-%m-%d %H:%M:%S'), end_time.strftime('%Y-%m-%d %H:%M:%S')]
for keyword in Doonsec:
params.append(f'%{keyword}%')
params = [
two_days_ago.strftime('%Y-%m-%d %H:%M:%S'),
now.strftime('%Y-%m-%d %H:%M:%S')
] + [f'%{keyword}%' for keyword in Doonsec]
# 执行查询
cursor.execute(query, params)
results = cursor.fetchall()
if results:
for row in results:
user_id = row[0]
cursor.execute('''
UPDATE articles
SET is_sended = True
WHERE id = ?
''', (user_id,))
conn.commit() # 提交事务
conn.close()
return results
@@ -150,13 +171,13 @@ def get_filtered_articles(entries, Is_short):
return result
def Src_doonsec(e_hour, Is_short, Doonsec_switch, Doonsec):
def Src_doonsec(Is_short, Doonsec_switch, Doonsec):
if not os.path.exists('./resources/db/doonsec.db'):
# 创建数据库和表
create_database()
# 清空表
clear_table()
# clear_table()
# 获取 JSON 数据
M_doonsec_data = get_doonsec_json()
@@ -165,7 +186,7 @@ def Src_doonsec(e_hour, Is_short, Doonsec_switch, Doonsec):
insert_data(M_doonsec_data)
# 查询指定时间段内的数据
filtered_articles = select_articles(e_hour, Doonsec_switch, Doonsec)
filtered_articles = select_articles(Doonsec_switch, Doonsec)
# print(filtered_articles)
if filtered_articles:
@@ -175,7 +196,7 @@ def Src_doonsec(e_hour, Is_short, Doonsec_switch, Doonsec):
return False
if __name__ == "__main__":
reslts = Src_doonsec(24, False, True, ["webshell", "2000", "POC"] )
reslts = Src_doonsec(False, True, ["webshell", "2000", "POC", "SQL", "XSS", "CSRF", "漏洞"] )
if reslts != False:
print(reslts)
else: