init: python flask demo

This commit is contained in:
zzy
2026-10-28 22:40:03 +08:00
commit 1b12670f55
3 changed files with 64 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
from flask import Flask, jsonify
import socket, os, sys, platform, datetime
app = Flask(__name__)
@app.route('/')
def index():
return f"""<!DOCTYPE html>
<html><head><title>Python Demo</title>
<style>
body{{font-family:system-ui,-apple-system,sans-serif;max-width:760px;margin:60px auto;padding:0 20px;background:#0f1117;color:#e6edf3}}
h1{{color:#58a6ff;border-bottom:1px solid #30363d;padding-bottom:12px}}
table{{border-collapse:collapse;width:100%;margin-top:16px}}
td{{padding:10px 12px;border-bottom:1px solid #21262d}}
td:first-child{{color:#8b949e;width:160px}}
.badge{{display:inline-block;background:#238636;color:#fff;padding:2px 10px;border-radius:12px;font-size:13px}}
code{{background:#161b22;padding:2px 6px;border-radius:4px;color:#79c0ff}}
</style></head><body>
<h1>?? Python Demo <span class="badge">RUNNING</span></h1>
<table>
<tr><td>?????</td><td><code>{socket.gethostname()}</code></td></tr>
<tr><td>Python ??</td><td><code>{sys.version.split()[0]}</code></td></tr>
<tr><td>??</td><td><code>{platform.platform()}</code></td></tr>
<tr><td>Flask</td><td><code>{__import__('flask').__version__}</code></td></tr>
<tr><td>????</td><td><code>{datetime.datetime.now().isoformat()}</code></td></tr>
<tr><td>?? Host</td><td><code>{__import__('flask').request.host}</code></td></tr>
</table>
<p style="margin-top:32px;color:#8b949e">??????????? ? 47 nginx??????? ? kali Traefik ? ???</p>
<p style="color:#8b949e">API: <a href="/health" style="color:#58a6ff">/health</a> ? <a href="/api/time" style="color:#58a6ff">/api/time</a></p>
</body></html>"""
@app.route('/health')
def health():
return jsonify(status='ok', host=socket.gethostname())
@app.route('/api/time')
def api_time():
return jsonify(now=datetime.datetime.now().isoformat(), tz=str(datetime.datetime.now().astimezone().tzinfo))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False)