diff --git a/UpdateLOG.md b/UpdateLOG.md index f10f97f..6f4bb32 100644 --- a/UpdateLOG.md +++ b/UpdateLOG.md @@ -12,7 +12,7 @@ - 添加更多RSS订阅源(持续进行中) - 添加更多推送方式,如邮件、微信等 - 添加谷歌搜索等更多相关检测源,后续将支持谷歌语法 -- 添加性能限制模块 +- 将搜狗-微信和GitHub同步上网站推送 ### 下一步计划(已完成) - 将所有打印信息转为logging info并存档(已完成)
@@ -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日下午:上线了百度搜索内容监测 \ No newline at end of file +- 2025年01月10日下午:上线了百度搜索内容监测 +- 2025年01月14日晚:添加了网站读取文件逻辑仅读取限制数量的文件,避免文件过大导致程序崩溃或是阅读困难 \ No newline at end of file diff --git a/resources/log/core.log b/resources/log/core.log index 8b13789..e69de29 100644 --- a/resources/log/core.log +++ b/resources/log/core.log @@ -1 +0,0 @@ - diff --git a/web/app.py b/web/app.py index c5b38d8..6e2d947 100644 --- a/web/app.py +++ b/web/app.py @@ -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 \ No newline at end of file + app.run(debug=True) # 在生产环境中应设置为 False \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html index 13f1ec6..cc8f62a 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -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; /* 可选:鼠标悬停时显示下划线 */ + } }

历史推送读取


-
+
+

为保证网页运作性能,默认仅读取前20条记录,若您有需求可自行更改app.py

diff --git a/web/templates/log.html b/web/templates/log.html index de4dec5..716c416 100644 --- a/web/templates/log.html +++ b/web/templates/log.html @@ -22,6 +22,7 @@

程序运行日志

+

为保证网页运作性能,默认仅读取后100条记录,若您有需求可自行更改app.py


{{ log_content }}