import os import sys from flask import Flask, render_template_string import markdown 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('/') @app.route('/health') def health_check(): 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 Dashboard

System Status ONLINE

MQL5 Trading Automation is running.

{{ html_verification|safe }}

Project Documentation

{{ html_readme|safe }}
""", html_readme=html_readme, html_verification=html_verification, year=2026) except Exception as e: return f"Error: {str(e)}", 500 if __name__ == '__main__': port = int(os.environ.get('PORT', 8080)) print(f"Starting web dashboard on port {port}...") app.run(host='0.0.0.0', port=port)