NoteDiscovery/run.py

83 lines
2.2 KiB
Python
Raw Normal View History

2025-11-05 16:48:41 +00:00
#!/usr/bin/env python3
"""
Quick start script for NoteDiscovery
Run this to start the application without Docker
"""
import sys
import os
2025-11-05 16:48:41 +00:00
import subprocess
from pathlib import Path
2026-01-02 15:57:15 +00:00
try:
import colorama
colorama.just_fix_windows_console()
except ImportError:
colorama = None
2026-01-16 11:12:51 +00:00
def get_port():
"""Get port from: 1) ENV variable, 2) config.yaml, 3) default 8000"""
# Priority 1: Environment variable
if os.getenv("PORT"):
return os.getenv("PORT")
# Priority 2: config.yaml
config_path = Path("config.yaml")
if config_path.exists():
try:
import yaml
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
if config and 'server' in config and 'port' in config['server']:
return str(config['server']['port'])
except Exception:
pass # Fall through to default
# Priority 3: Default
return "8000"
2025-11-05 16:48:41 +00:00
def main():
print("🚀 Starting NoteDiscovery...\n")
# Check if requirements are installed
try:
import fastapi
import uvicorn
except ImportError:
print("📦 Installing dependencies...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
# Create data directories
Path("data").mkdir(parents=True, exist_ok=True)
2025-11-05 16:48:41 +00:00
Path("plugins").mkdir(parents=True, exist_ok=True)
2026-01-16 11:12:51 +00:00
# Get port from config or environment
port = get_port()
2025-11-05 16:48:41 +00:00
print("✓ Dependencies installed")
print("✓ Directories created")
print("\n" + "="*50)
print("🎉 NoteDiscovery is running!")
print("="*50)
print(f"\n📝 Open your browser to: http://localhost:{port}")
2025-11-05 16:48:41 +00:00
print("\n💡 Tips:")
print(" - Press Ctrl+C to stop the server")
print(" - Your notes are in ./data/")
2025-11-05 16:48:41 +00:00
print(" - Plugins go in ./plugins/")
print(f" - Change port with: PORT={port} python run.py")
2025-11-05 16:48:41 +00:00
print("\n" + "="*50 + "\n")
# Run the application
subprocess.call([
sys.executable, "-m", "uvicorn",
"backend.main:app",
"--reload",
"--host", "0.0.0.0",
2026-01-18 15:00:01 +00:00
"--port", port,
"--timeout-graceful-shutdown", "2"
2025-11-05 16:48:41 +00:00
])
if __name__ == "__main__":
main()