This commit is contained in:
MasonLiu 2025-01-14 18:16:59 +08:00
parent e3ccf0db0d
commit 61f505d439
5 changed files with 40 additions and 9 deletions

View File

@ -12,7 +12,7 @@
- 添加更多RSS订阅源持续进行中
- 添加更多推送方式,如邮件、微信等
- 添加谷歌搜索等更多相关检测源,后续将支持谷歌语法
- 添加性能限制模块
- 将搜狗-微信和GitHub同步上网站推送
### 下一步计划(已完成)
- 将所有打印信息转为logging info并存档已完成<br>
@ -24,6 +24,7 @@
- 更换筛选模块,由时段筛选改为历史记录筛选以确保不会有资讯漏报(筛选条件增加了时间筛选和是否已发送筛选)
- 添加GitHub等监测源重构参考项目逻辑并上线
- 添加百度监测源
- 添加性能限制模块(限制每次读取数量)
### 下一步计划(已作废)
- 添加Mysql作为数据库存储现有sqlite已满足使用
@ -43,4 +44,5 @@
- 2025年01月05日晚修复了doonsec相关配置的bug程序现已可正常运行
- 2025年01月06日更新了配置信息自动获取的逻辑添加关键词等现可在运行时添加重要配置信息config.yaml仍需暂停重新运行
- 2025年01月10日上午修复了github推送的问题时区消息配置错误等
- 2025年01月10日下午上线了百度搜索内容监测
- 2025年01月10日下午上线了百度搜索内容监测
- 2025年01月14日晚添加了网站读取文件逻辑仅读取限制数量的文件避免文件过大导致程序崩溃或是阅读困难

View File

@ -1 +0,0 @@

View File

@ -1,4 +1,5 @@
from flask import Flask, jsonify, render_template
from collections import deque
import os
import logging
@ -29,6 +30,17 @@ def index():
logging.info("访问主页")
return render_template('index.html')
def get_records(content, num_records=20, delimiter='-'*40):
records = content.split(delimiter)
# 去除空字符串去除之后MD格式会混乱
# records = [record.strip() for record in records if record.strip()]
selected_records = records[:num_records]
return delimiter.join(selected_records)
def read_last_lines(file_path, num_lines=100):
with open(file_path, 'r', encoding='utf-8') as file:
return deque(file, maxlen=num_lines)
@app.route('/get-sec-news')
def get_sec_news():
logging.info(f"尝试打开安全新闻历史推送文件: {SEC_NEWS_PATH}")
@ -36,6 +48,7 @@ def get_sec_news():
with open(SEC_NEWS_PATH, 'r', encoding='utf-8') as file:
content = file.read()
content = replace_content(content)
content = get_records(content)
return jsonify({'content': content}), 200
except FileNotFoundError:
logging.error(f"文件缺失: {SEC_NEWS_PATH}")
@ -51,6 +64,7 @@ def get_tech_passage():
with open(TECH_PASSAGE_PATH, 'r', encoding='utf-8') as file:
content = file.read()
content = replace_content(content)
content = get_records(content)
return jsonify({'content': content}), 200
except FileNotFoundError:
logging.error(f"文件缺失: {TECH_PASSAGE_PATH}")
@ -63,16 +77,16 @@ def get_tech_passage():
def get_log():
logging.info(f"尝试打开核心日志文件: {CORE_LOG_PATH}")
# 读取日志文件内容
with open(CORE_LOG_PATH, 'r', encoding='utf-8') as file:
log_content = file.read()
log_content = read_last_lines(CORE_LOG_PATH)
log_content = '\n'.join(log_content)
# 将日志内容传递给模板
return render_template('log.html', log_content=log_content)
@app.route('/weblog')
def get_weblog():
logging.info(f"尝试打开Web应用日志文件: {WEB_LOG_PATH}")
with open(WEB_LOG_PATH, 'r') as file:
log_content = file.read()
log_content = read_last_lines(WEB_LOG_PATH)
log_content = '\n'.join(log_content)
log_content = replace_content(log_content)
return render_template('log.html', log_content=log_content)
@ -80,4 +94,4 @@ def run_server():
app.run(host='0.0.0.0', port=5000)
if __name__ == '__main__':
app.run(debug=False) # 在生产环境中应设置为 False
app.run(debug=True) # 在生产环境中应设置为 False

View File

@ -39,6 +39,13 @@
#back-to-top:hover {
background-color: #777;
}
#markdown-content a {
color: blue;
text-decoration: none; /* 可选:去掉下划线 */
}
#markdown-content a:hover {
text-decoration: underline; /* 可选:鼠标悬停时显示下划线 */
}
/* 移动端样式调整 */
@media only screen and (max-width: 600px) {
@ -55,13 +62,21 @@
font-size: 14px;
padding: 8px;
}
#markdown-content a {
color: blue;
text-decoration: none; /* 可选:去掉下划线 */
}
#markdown-content a:hover {
text-decoration: underline; /* 可选:鼠标悬停时显示下划线 */
}
}
</style>
</head>
<body>
<div class="layui-container">
<center><h1 class="layui-title" id="page-title">历史推送读取</h1><br>
<button id="toggle-fetch-btn" class="layui-btn">切换读取源</button><br></center>
<button id="toggle-fetch-btn" class="layui-btn">切换读取源</button><br>
<h4>为保证网页运作性能默认仅读取前20条记录若您有需求可自行更改app.py</h4></center>
<div id="markdown-content" class="layui-card-body"></div>
</div>

View File

@ -22,6 +22,7 @@
<body>
<div class="layui-container">
<h1 class="layui-title">程序运行日志</h1>
<h4>为保证网页运作性能默认仅读取后100条记录若您有需求可自行更改app.py</h4><br>
<pre>{{ log_content }}</pre>
<div id="markdown-content" class="layui-card-body"></div>
</div>