from flask import Flask, jsonify
from flask_cors import CORS
import logging
import os

app = Flask(__name__)
CORS(app)  # 允许跨域访问

# 配置日志
# 确保logs目录存在
logs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'handlers', 'Rankings', 'logs')
os.makedirs(logs_dir, exist_ok=True)

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(os.path.join(logs_dir, 'app.log'), encoding='utf-8'),
        logging.StreamHandler()
    ]
)

# 导入并注册蓝图
from routers.rank_api_routes import rank_bp
from routers.article_routes import article_bp
app.register_blueprint(rank_bp)
app.register_blueprint(article_bp)


if __name__ == '__main__':
    print("启动主程序服务...")
    print("服务地址: http://localhost:5001")

    app.run(host='0.0.0.0', port=5001, debug=True)