import importlib.util
import sys
from pathlib import Path
from flask import Flask, render_template_string
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
sys.path.insert(0, str(Path(__file__).parent))
CATEGORIES = ["personal", "home", "work"]
root = Flask(__name__)
def _discover_apps():
apps = []
base = Path(__file__).parent
for category in CATEGORIES:
cat_dir = base / category
if not cat_dir.is_dir():
continue
for app_dir in sorted(cat_dir.iterdir()):
if app_dir.is_dir() and (app_dir / "app.py").exists():
apps.append((category, app_dir.name))
return apps
@root.route("/")
def index():
apps = _discover_apps()
grouped: dict[str, list[tuple[str, str]]] = {}
for category, app_name in apps:
grouped.setdefault(category, []).append((category, app_name))
sections = ""
delay = 0
for category in CATEGORIES:
if category not in grouped:
continue
items_html = ""
for cat, name in grouped[category]:
items_html += (
f''
f'\u203a'
f'
Flask applications