-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
104 lines (91 loc) · 3.42 KB
/
launcher.py
File metadata and controls
104 lines (91 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
QuirkLog 每日计划与总结应用程序启动器
Web版本专用启动器
"""
import sys
from datetime import datetime
def run_web_version():
"""运行Web版本"""
print("🌐 启动Web版本...")
try:
import web_server
web_server.main() # web_server.main() 现在会处理计划监听器的停止
except Exception as e:
print(f"❌ Web版本启动失败: {e}")
return False
return True
def start_weekly_task_background():
"""在后台启动定时任务"""
try:
import weekly_task
task_manager = weekly_task.WeeklyTaskManager()
task_manager.start()
print("✅ 定时任务已在后台启动")
return task_manager
except Exception as e:
print(f"⚠️ 定时任务启动失败: {e}")
return None
def start_plan_monitor_background():
"""在后台启动计划监听器"""
try:
import plan_monitor
monitor = plan_monitor.PlanMonitor()
monitor.start()
print("✅ 计划监听器已在后台启动")
return monitor
except Exception as e:
print(f"⚠️ 计划监听器启动失败: {e}")
return None
def main():
"""主函数"""
today = datetime.now().strftime("%Y年%m月%d日")
print(f"🌞 {today} QuirkLog 每日计划与总结应用程序")
print("=" * 50)
# 检查命令行参数
if len(sys.argv) > 1:
if sys.argv[1] == "--web" or sys.argv[1] == "-w":
if run_web_version():
# 启动后在后台运行定时任务
start_weekly_task_background()
# 启动计划监听器
start_plan_monitor_background()
return
elif sys.argv[1] == "--task" or sys.argv[1] == "-t":
print("⏰ 启动定时任务管理器...")
try:
import weekly_task
weekly_task.main()
except Exception as e:
print(f"❌ 定时任务启动失败: {e}")
return
elif sys.argv[1] == "--help" or sys.argv[1] == "-h":
print("\n使用说明:")
print(" python launcher.py # 启动Web版本")
print(" python launcher.py --web # 启动Web版本")
print(" python launcher.py --task # 启动定时任务管理器")
print(" python launcher.py --help # 显示帮助信息")
print("\n功能说明:")
print(" - Web版本: 现代化浏览器界面,支持计划管理和总结功能")
print(" - 定时任务: AI每周洞察自动生成,需要配置OpenRouter API")
print(" - 计划监听器: 实时监听今日计划,到时间自动弹窗提醒")
return
# 默认启动Web版本
print("🚀 正在启动应用程序...")
monitor = None
try:
if run_web_version():
# 在后台启动定时任务
start_weekly_task_background()
# 在后台启动计划监听器
monitor = start_plan_monitor_background()
except KeyboardInterrupt:
print("\n👋 收到退出信号")
# 确保在程序退出时停止计划监听器
if monitor and monitor.is_running():
print("🛑 正在停止计划监听器...")
monitor.stop()
print("✅ 计划监听器已安全关闭")
if __name__ == "__main__":
main()