CoolFace
Apppublic

BluefxPraise/The_Oracle

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
main.py59 linesDownload Raw Back to root
1"""The Oracle — main entrypoint.2 3Boots DB, Flask dashboard, scheduler, keep-alive, and Telegram polling.4"""5 6import logging7import sys8 9import memory10from brain import Brain11from interface import telegram_ui, web_dashboard12from utils import scheduler as sched_mod13from utils.keep_alive import start_keep_alive14 15logging.basicConfig(16    level=logging.INFO,17    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",18    handlers=[logging.StreamHandler(sys.stdout)],19)20log = logging.getLogger("oracle.main")21 22 23def main():24    log.info("🧠 The Oracle booting…")25 26    # 1. Init DB (auto-creates default group on first run)27    memory.init_db()28    log.info("DB initialized at %s", memory.DB_PATH)29 30    # 2. Brain (sets phase=OBSERVATION on first run)31    brain = Brain()32    log.info("Brain initialized — phase=%s", brain.phase())33 34    # 3. Build Telegram Application (not started yet — webhook mode)35    tg_app = telegram_ui.build_app(brain)36 37    # 4. Web dashboard (Flask in background thread; owns :7860 + /telegram webhook)38    web_dashboard.start_in_thread(tg_app=tg_app)39 40    # 5. Scheduler (background)41    sched_mod.setup(brain)42 43    # 6. Keep-alive + heartbeat44    start_keep_alive()45 46    # 7. Run an initial pass so DB has fresh data on first boot47    try:48        brain.refresh_news()49    except Exception:50        log.exception("initial refresh_news failed")51 52    # 8. Telegram webhook (blocks; initializes Application and registers webhook)53    log.info("Starting Telegram webhook — The Oracle is online")54    telegram_ui.run(tg_app)55 56 57if __name__ == "__main__":58    main()59