forked from officiallyutso/Founder-OS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (65 loc) · 2.31 KB
/
Copy pathmain.py
File metadata and controls
83 lines (65 loc) · 2.31 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
import asyncio
import logging
import os
import sys
import threading
# Make all output UTF-8 safe so emojis never crash on a Windows cp1252 console.
for _stream in (sys.stdout, sys.stderr):
try:
_stream.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
from config import config
from memory.paths import ensure_data_dirs, subpath
ensure_data_dirs()
_log_file = subpath("logs", "founder_os.log")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler(_log_file, encoding="utf-8"),
],
)
logger = logging.getLogger(__name__)
def _start_scheduler_async():
"""Run APScheduler on a dedicated asyncio loop (web-only or alongside Telegram)."""
from scheduler.jobs import start_scheduler
def _run():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
start_scheduler(None)
loop.run_forever()
t = threading.Thread(target=_run, daemon=True, name="scheduler")
t.start()
return t
def _start_telegram():
from telegram.ext import ApplicationBuilder
from bot.handlers import register_handlers
from scheduler.jobs import start_scheduler, set_bot
logger.info("Telegram channel enabled.")
app = ApplicationBuilder().token(config.telegram_bot_token).build()
register_handlers(app)
set_bot(app)
start_scheduler(app)
logger.info("Bot is running on Telegram.")
app.run_polling(drop_pending_updates=True)
def main():
logger.info(f"Starting Founder OS for {config.my_name} @ {config.company_name}")
if config.web_ui_enabled and config.telegram_enabled:
from dashboard.app import start_in_thread
start_in_thread()
logger.info(f"Web UI at http://127.0.0.1:{config.dashboard_port}")
if config.telegram_enabled:
if not config.web_ui_enabled:
_start_scheduler_async()
_start_telegram()
return
# Web-only mode: scheduler + single blocking web server (no duplicate bind)
_start_scheduler_async()
if config.web_ui_enabled:
logger.info("Running in web-only mode. Open the Web UI in your browser.")
from dashboard.app import run_blocking
run_blocking()
if __name__ == "__main__":
main()