first commit

This commit is contained in:
wildercayden 2025-06-24 11:17:01 -04:00
commit 8cfce22478

47
my website/App.py Normal file
View File

@ -0,0 +1,47 @@
from flask import Flask
import psutil
app = Flask(__name__)
@app.route("/")
def home():
cpu = psutil.cpu_percent(interval=0.5)
mem = psutil.virtual_memory()
temps = psutil.sensors_temperatures()
cputemp = "Unavailable"
for label in ["coretemp", "cpu-thermal", "k10temp", "cpu_thermal"]:
if label in temps and temps[label]:
cputemp = f"{temps[label][0].current:.1f}"
break
else:
# to force it to work when on PI
try:
with open("/sys/class/thermal/thermal_zone0/temp") as f:
cputemp = f"{int(f.read()) / 1000:.1f}"
except:
pass
return f"""
<!DOCTYPE html>
<html>
<head>
<title>Simple System Monitor</title>
<meta http-equiv="refresh" content="5">
<style>
body {{ font-family: monospace; background: #222; color: #eee; padding: 20px; }}
h1 {{ color: #0f0; }}
.stat {{ margin-bottom: 10px; }}
</style>
</head>
<body>
<h1>System Monitor</h1>
<div class="stat">CPU Usage: {cpu}%</div>
<div class="stat">Memory Usage: {mem.percent}% ({mem.used // (1024**2)} MB used / {mem.total // (1024**2)} MB total)</div>
<div class="stat">CPU Temp: {cputemp}C</div>
</body>
</html>
"""
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)