🚀 Project optimization and cleanup
- Remove deprecated generate_documentation.py (2187 lines, 71MB HTML output) - Remove unused comprehensive_workflow_renamer.py (396 lines) - Replace import-workflows.sh with Python import_workflows.py (better error handling) - Remove Chinese README to simplify project structure - Enhance run.py with CLI arguments and better configuration - Update requirements.txt with precise version constraints - Overall: Removed ~2600+ lines of unused/deprecated code - Improved: Error handling, logging, and development workflow
This commit is contained in:
131
run.py
131
run.py
@@ -1,56 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
🚀 Simple Launcher for n8n-workflows Search Engine
|
||||
Start the system with advanced search capabilities.
|
||||
🚀 N8N Workflows Search Engine Launcher
|
||||
Start the advanced search system with optimized performance.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def print_banner():
|
||||
"""Print application banner."""
|
||||
print("🚀 n8n-workflows Advanced Search Engine")
|
||||
print("=" * 50)
|
||||
|
||||
def check_requirements():
|
||||
"""Check if requirements are installed."""
|
||||
|
||||
def check_requirements() -> bool:
|
||||
"""Check if required dependencies are installed."""
|
||||
missing_deps = []
|
||||
|
||||
try:
|
||||
import sqlite3
|
||||
except ImportError:
|
||||
missing_deps.append("sqlite3")
|
||||
|
||||
try:
|
||||
import uvicorn
|
||||
except ImportError:
|
||||
missing_deps.append("uvicorn")
|
||||
|
||||
try:
|
||||
import fastapi
|
||||
print("✅ Dependencies verified")
|
||||
return True
|
||||
except ImportError as e:
|
||||
print(f"❌ Missing dependency: {e}")
|
||||
except ImportError:
|
||||
missing_deps.append("fastapi")
|
||||
|
||||
if missing_deps:
|
||||
print(f"❌ Missing dependencies: {', '.join(missing_deps)}")
|
||||
print("💡 Install with: pip install -r requirements.txt")
|
||||
return False
|
||||
|
||||
print("✅ Dependencies verified")
|
||||
return True
|
||||
|
||||
def setup_database():
|
||||
"""Setup database if needed."""
|
||||
|
||||
def setup_directories():
|
||||
"""Create necessary directories."""
|
||||
directories = ["database", "static", "workflows"]
|
||||
|
||||
for directory in directories:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
print("✅ Directories verified")
|
||||
|
||||
|
||||
def setup_database(force_reindex: bool = False) -> str:
|
||||
"""Setup and initialize the database."""
|
||||
from workflow_db import WorkflowDatabase
|
||||
|
||||
db_path = "database/workflows.db"
|
||||
os.makedirs("database", exist_ok=True)
|
||||
|
||||
print(f"🔄 Setting up database: {db_path}")
|
||||
db = WorkflowDatabase(db_path)
|
||||
|
||||
# Check if database has data
|
||||
# Check if database has data or force reindex
|
||||
stats = db.get_stats()
|
||||
if stats['total'] == 0:
|
||||
if stats['total'] == 0 or force_reindex:
|
||||
print("📚 Indexing workflows...")
|
||||
index_stats = db.index_all_workflows(force_reindex=True)
|
||||
print(f"✅ Indexed {index_stats['processed']} workflows")
|
||||
|
||||
# Show final stats
|
||||
final_stats = db.get_stats()
|
||||
print(f"📊 Database contains {final_stats['total']} workflows")
|
||||
else:
|
||||
print(f"✅ Database ready: {stats['total']} workflows")
|
||||
|
||||
return db_path
|
||||
|
||||
def start_server(port=8000):
|
||||
"""Start the API server."""
|
||||
print(f"🌐 Starting server at http://localhost:{port}")
|
||||
print(f"📊 API: http://localhost:{port}/api/workflows")
|
||||
print(f"🗂️ Categories: http://localhost:{port}/api/categories")
|
||||
|
||||
def start_server(host: str = "127.0.0.1", port: int = 8000, reload: bool = False):
|
||||
"""Start the FastAPI server."""
|
||||
print(f"🌐 Starting server at http://{host}:{port}")
|
||||
print(f"📊 API Documentation: http://{host}:{port}/docs")
|
||||
print(f"🔍 Workflow Search: http://{host}:{port}/api/workflows")
|
||||
print()
|
||||
print("Press Ctrl+C to stop the server")
|
||||
print("-" * 50)
|
||||
@@ -58,32 +91,86 @@ def start_server(port=8000):
|
||||
# Configure database path
|
||||
os.environ['WORKFLOW_DB_PATH'] = "database/workflows.db"
|
||||
|
||||
# Start uvicorn without reload to avoid StatReload issues
|
||||
# Start uvicorn with better configuration
|
||||
import uvicorn
|
||||
uvicorn.run("api_server:app", host="127.0.0.1", port=port, reload=False)
|
||||
uvicorn.run(
|
||||
"api_server:app",
|
||||
host=host,
|
||||
port=port,
|
||||
reload=reload,
|
||||
log_level="info",
|
||||
access_log=False # Reduce log noise
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point with command line arguments."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="N8N Workflows Search Engine",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
python run.py # Start with default settings
|
||||
python run.py --port 3000 # Start on port 3000
|
||||
python run.py --host 0.0.0.0 # Accept external connections
|
||||
python run.py --reindex # Force database reindexing
|
||||
python run.py --dev # Development mode with auto-reload
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
default="127.0.0.1",
|
||||
help="Host to bind to (default: 127.0.0.1)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
type=int,
|
||||
default=8000,
|
||||
help="Port to bind to (default: 8000)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--reindex",
|
||||
action="store_true",
|
||||
help="Force database reindexing"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dev",
|
||||
action="store_true",
|
||||
help="Development mode with auto-reload"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print_banner()
|
||||
|
||||
# Check dependencies
|
||||
if not check_requirements():
|
||||
sys.exit(1)
|
||||
|
||||
# Setup directories
|
||||
setup_directories()
|
||||
|
||||
# Setup database
|
||||
try:
|
||||
setup_database()
|
||||
setup_database(force_reindex=args.reindex)
|
||||
except Exception as e:
|
||||
print(f"❌ Database setup error: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Start server
|
||||
try:
|
||||
start_server()
|
||||
start_server(
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
reload=args.dev
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("\n👋 Server stopped!")
|
||||
except Exception as e:
|
||||
print(f"❌ Server error: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user