import os import sys from flask import Flask, render_template_string, jsonify import markdown import time app = Flask(__name__) # Cache storage: filepath -> (mtime, html_content) _content_cache = {} def get_cached_markdown(filepath): """ Returns the markdown content of a file converted to HTML, using a cache that invalidates based on file modification time. """ if not os.path.exists(filepath): return None try: mtime = os.path.getmtime(filepath) if filepath in _content_cache: cached_mtime, cached_html = _content_cache[filepath] if cached_mtime == mtime: return cached_html # Cache miss or file changed with open(filepath, 'r', encoding='utf-8') as f: content = f.read() html_content = markdown.markdown(content) _content_cache[filepath] = (mtime, html_content) return html_content except Exception as e: print(f"Error reading/converting {filepath}: {e}") return None @app.route('/health') def health_check(): """Lightweight health check for load balancers.""" return jsonify({ "status": "healthy", "timestamp": time.time() }) @app.route('/') def dashboard(): try: base_dir = os.path.dirname(os.path.abspath(__file__)) readme_path = os.path.join(base_dir, '..', 'README.md') verification_path = os.path.join(base_dir, '..', 'VERIFICATION.md') html_readme = get_cached_markdown(readme_path) or "
README.md not found.
" html_verification = get_cached_markdown(verification_path) or "VERIFICATION.md not found.
" return render_template_string("""MQL5 Trading Automation is running.
{{ html_verification|safe }}