#!/usr/bin/env python3
"""Flask-сервер для просмотра базы знаний сноубайков."""

import sys
sys.path.insert(0, '/home/node/.local/lib/python3.11/site-packages')

from flask import Flask, send_from_directory, send_file
from pathlib import Path

app = Flask(__name__)

BASE_DIR    = Path(__file__).parent
VIEWER_DIR  = BASE_DIR / 'viewer'
KB_FILE     = Path('/home/node/.openclaw/workspace/data/telegram-collector/knowledge_base.md')


@app.route('/snowbike/')
@app.route('/snowbike')
def index():
    return send_from_directory(VIEWER_DIR, 'index.html')


@app.route('/snowbike/knowledge_base.md')
def knowledge_base():
    if not KB_FILE.exists():
        return 'Not ready yet', 404
    return send_file(KB_FILE, mimetype='text/plain; charset=utf-8')


if __name__ == '__main__':
    print('🏔 Snowbike KB viewer: http://localhost:5556/snowbike/')
    app.run(host='0.0.0.0', port=5556, debug=False)
