This commit is contained in:
MasonLiu committed 2024-12-15 02:14:39 +08:00
1 parent 3c83bd6602
commit 574fc326cd
29 files changed
+1826 -1635

No files matched your search

+76 -9
View File
@@ -1,3 +1,64 @@
# from flask import Flask, jsonify, render_template
# import os
# app = Flask(__name__)
# # 配置文件路径
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# PARENT_DIR = os.path.dirname(BASE_DIR) # 上一个文件夹
# SEC_NEWS_PATH = os.path.join(PARENT_DIR, 'history', 'sec_news.md')
# TECH_PASSAGE_PATH = os.path.join(PARENT_DIR, 'history', 'tech_passage.md')
# # print(f"Sec News Path: {SEC_NEWS_PATH}")
# # print(f"Tech Passage Path: {TECH_PASSAGE_PATH}")
# @app.route('/')
# def index():
# return render_template('index.html')
# # 替换输出内容
# def replace_content(content):
# content = content.replace('####', '###')
# # content = content.replace('\n\n', '###')
# return content
# @app.route('/get-sec-news')
# def get_sec_news():
# print(f"尝试打开安全新闻历史推送文件: {SEC_NEWS_PATH}")
# try:
# with open(SEC_NEWS_PATH, 'r', encoding='utf-8') as file:
# content = file.read()
# content = replace_content(content)
# return jsonify({'content': content}), 200
# except FileNotFoundError:
# print(f"文件缺失: {SEC_NEWS_PATH}")
# return jsonify({'error': '安全新闻历史推送文件缺失!'}), 404
# except Exception as e:
# print(f"读取时出错: {SEC_NEWS_PATH}, 原因: {str(e)}")
# return jsonify({'error': str(e)}), 500
# @app.route('/get-tech-passage')
# def get_tech_passage():
# print(f"尝试打开技术文章历史推送文件: {TECH_PASSAGE_PATH}")
# try:
# with open(TECH_PASSAGE_PATH, 'r', encoding='utf-8') as file:
# content = file.read()
# content = replace_content(content)
# return jsonify({'content': content}), 200
# except FileNotFoundError:
# print(f"文件缺失: {TECH_PASSAGE_PATH}")
# return jsonify({'error': '技术文章历史推送文件缺失!'}), 404
# except Exception as e:
# print(f"读取时出错: {TECH_PASSAGE_PATH}, 原因: {str(e)}")
# return jsonify({'error': str(e)}), 500
# def run_server():
# app.run(host='0.0.0.0', port=5000)
# if __name__ == '__main__':
# app.run(debug=False) # 在生产环境中应设置为 False
#file:e:\Self-Tool-Code\PyBot\web\app.py
from flask import Flask, jsonify, render_template
import os
@@ -8,20 +69,17 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.dirname(BASE_DIR) # 上一个文件夹
SEC_NEWS_PATH = os.path.join(PARENT_DIR, 'history', 'sec_news.md')
TECH_PASSAGE_PATH = os.path.join(PARENT_DIR, 'history', 'tech_passage.md')
# print(f"Sec News Path: {SEC_NEWS_PATH}")
# print(f"Tech Passage Path: {TECH_PASSAGE_PATH}")
@app.route('/')
def index():
return render_template('index.html')
CORE_LOG_PATH = os.path.join(PARENT_DIR, 'log', 'core.log') # 新增日志文件路径
# 替换输出内容
def replace_content(content):
content = content.replace('####', '###')
# content = content.replace('\n\n', '###')
return content
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get-sec-news')
def get_sec_news():
print(f"尝试打开安全新闻历史推送文件: {SEC_NEWS_PATH}")
@@ -52,8 +110,17 @@ def get_tech_passage():
print(f"读取时出错: {TECH_PASSAGE_PATH}, 原因: {str(e)}")
return jsonify({'error': str(e)}), 500
@app.route('/log')
def get_log():
print(f"尝试打开核心日志文件: {CORE_LOG_PATH}")
# 读取日志文件内容
with open(CORE_LOG_PATH, 'r', encoding='utf-8') as file:
log_content = file.read()
# 将日志内容传递给模板
return render_template('log.html', log_content=log_content)
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
+53
View File
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>日志查询</title>
<!-- 引入 Layui 的 CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
color: #333;
}
#markdown-content {
white-space: pre-wrap; /* Preserve whitespace and wrap lines */
}
</style>
</head>
<body>
<div class="layui-container">
<h1 class="layui-title">程序运行日志</h1>
<pre>{{ log_content }}</pre>
<div id="markdown-content" class="layui-card-body"></div>
</div>
<!-- 引入 Layui 的 JS -->
<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.js"></script>
<!-- <script>
layui.use(['layer'], function(){
var layer = layui.layer;
fetch('/get-log')
.then(response => response.json())
.then(data => {
if (data.content) {
const htmlContent = marked.parse(data.content);
document.getElementById('markdown-content').innerHTML = htmlContent;
} else {
document.getElementById('markdown-content').innerHTML = '<p>Error loading markdown.</p>';
}
})
.catch(error => {
console.error('Error fetching the markdown:', error);
document.getElementById('markdown-content').innerHTML = '<p>Failed to load markdown.</p>';
layer.msg('Failed to load markdown.', {icon: 5});
});
});
</script> -->
</body>
</html>