#!/usr/bin/env python3
"""
数据提取与转换器 - 启动脚本
专为大学生开发的多功能数据处理工具
"""

import os
import sys
from app import app

def check_dependencies():
    """检查必要的依赖是否安装"""
    try:
        import flask
        import pandas
        import requests
        import fitz  # PyMuPDF
        import pytesseract
        import sqlalchemy
        print("✓ 所有依赖包已安装")
        return True
    except ImportError as e:
        print(f"✗ 缺少依赖包: {e}")
        print("请运行: pip install -r requirements.txt")
        return False

def create_upload_directories():
    """创建必要的上传目录"""
    directories = ['uploads', 'static', 'templates']
    
    for directory in directories:
        os.makedirs(directory, exist_ok=True)
    
    print("✓ 目录结构已创建")

def main():
    """主函数"""
    print("=" * 50)
    print("数据提取与转换器 - 大学生专用工具")
    print("=" * 50)
    
    # 检查依赖
    if not check_dependencies():
        sys.exit(1)
    
    # 创建目录
    create_upload_directories()
    
    print("\n启动信息:")
    print("- 本地访问: http://localhost:5000")
    print("- 网络访问: http://0.0.0.0:5000")
    print("- 停止服务: Ctrl+C")
    print("\n" + "=" * 50)
    
    # 启动Flask应用
    try:
        app.run(debug=True, host='0.0.0.0', port=5000)
    except KeyboardInterrupt:
        print("\n\n服务已停止")
    except Exception as e:
        print(f"\n\n启动失败: {e}")

if __name__ == '__main__':
    main()