Files
worklist/start.py
2025-12-30 09:03:29 +00:00

96 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
工作任务管理系统启动脚本
"""
import os
import sys
import subprocess
import webbrowser
import time
from pathlib import Path
def check_python_version():
"""检查Python版本"""
if sys.version_info < (3, 7):
print("错误: 需要Python 3.7或更高版本")
sys.exit(1)
def install_dependencies():
"""安装依赖"""
print("正在安装Python依赖...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "backend/requirements.txt"])
print("✓ Python依赖安装完成")
except subprocess.CalledProcessError as e:
print(f"错误: 安装依赖失败 - {e}")
sys.exit(1)
def create_env_file():
"""创建环境变量文件"""
env_file = Path("backend/.env")
if not env_file.exists():
print("创建环境变量文件...")
with open(env_file, "w", encoding="utf-8") as f:
f.write("""# OpenAI API配置可选用于AI润色功能
OPENAI_API_KEY=your_openai_api_key_here
# 数据库配置
DATABASE_URL=sqlite:///worklist.db
# Flask配置
SECRET_KEY=your-secret-key-here
""")
print("✓ 环境变量文件已创建: backend/.env")
print("提示: 如需使用AI润色功能请在.env文件中设置OPENAI_API_KEY")
def start_server():
"""启动服务器"""
print("正在启动服务器...")
os.chdir("backend")
try:
# 启动Flask应用
subprocess.run([sys.executable, "app.py"])
except KeyboardInterrupt:
print("\n服务器已停止")
except Exception as e:
print(f"错误: 启动服务器失败 - {e}")
sys.exit(1)
def main():
"""主函数"""
print("=" * 50)
print("工作任务管理系统")
print("=" * 50)
# 检查Python版本
check_python_version()
# 安装依赖
install_dependencies()
# 创建环境变量文件
create_env_file()
print("\n启动说明:")
print("1. 服务器启动后,请在浏览器中访问: http://localhost:5000")
print("2. 按 Ctrl+C 停止服务器")
print("3. 如需使用AI润色功能请配置OpenAI API密钥")
print("\n正在启动服务器...")
# 延迟2秒后自动打开浏览器
def open_browser():
time.sleep(2)
webbrowser.open("http://localhost:5000")
import threading
browser_thread = threading.Thread(target=open_browser)
browser_thread.daemon = True
browser_thread.start()
# 启动服务器
start_server()
if __name__ == "__main__":
main()