初始化参数数据自动化管理系统
功能: - 文章内容库管理 - 待处理产品列表管理 - 自动处理流程 - 智能搜索和数据提取 - ParamHub API集成 - 定时任务调度 部署端口: 16043
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
参数数据自动化管理系统
|
||||
"""
|
||||
from flask import Flask, jsonify
|
||||
from flask_cors import CORS
|
||||
from config import Config
|
||||
from models.database import db
|
||||
from utils.scheduler import task_scheduler, setup_auto_process_job
|
||||
import logging
|
||||
import os
|
||||
|
||||
# 配置日志
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler(os.path.join(Config.LOG_DIR, 'app.log')),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
logger = logging.getLogger('param_auto_manager')
|
||||
|
||||
# 创建Flask应用
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# 注册路由
|
||||
from routes.articles import bp as articles_bp
|
||||
from routes.products import bp as products_bp
|
||||
from routes.system import bp as system_bp
|
||||
|
||||
app.register_blueprint(articles_bp)
|
||||
app.register_blueprint(products_bp)
|
||||
app.register_blueprint(system_bp)
|
||||
|
||||
# 首页
|
||||
@app.route('/')
|
||||
def index():
|
||||
return jsonify({
|
||||
'name': 'Param Auto Manager',
|
||||
'version': '1.0.0',
|
||||
'description': '参数数据自动化管理系统',
|
||||
'endpoints': {
|
||||
'articles': '/api/articles',
|
||||
'products': '/api/products',
|
||||
'system': '/api/system'
|
||||
}
|
||||
})
|
||||
|
||||
# 错误处理
|
||||
@app.errorhandler(404)
|
||||
def not_found(error):
|
||||
return jsonify({'error': '资源不存在'}), 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_error(error):
|
||||
return jsonify({'error': '服务器内部错误'}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 确保日志目录存在
|
||||
os.makedirs(Config.LOG_DIR, exist_ok=True)
|
||||
os.makedirs(os.path.dirname(Config.DATABASE), exist_ok=True)
|
||||
|
||||
# 初始化数据库
|
||||
logger.info("初始化数据库...")
|
||||
|
||||
# 设置自动处理任务
|
||||
setup_auto_process_job()
|
||||
|
||||
# 启动定时任务调度器
|
||||
task_scheduler.start()
|
||||
logger.info("定时任务调度器已启动")
|
||||
|
||||
# 启动Flask应用
|
||||
logger.info(f"启动服务,端口: {Config.PORT}")
|
||||
app.run(
|
||||
host=Config.HOST,
|
||||
port=Config.PORT,
|
||||
debug=Config.DEBUG
|
||||
)
|
||||
Reference in New Issue
Block a user