finished uptime endpoint

This commit is contained in:
Ubergeek 2020-01-22 18:17:09 -05:00
parent 860f78f206
commit 3b4437db96
2 changed files with 27 additions and 3 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"python.pythonPath": "/usr/bin/python3",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}

View File

@ -1,9 +1,11 @@
#!/usr/bin/python3
# thunix_api.py
import flask
from flask import Flask, request, jsonify
import psutil, datetime
import psutil, datetime, time
app = Flask(__name__)
@ -26,8 +28,25 @@ def ip_info():
# uptime
@app.route("/uptime")
def uptime():
return str(datetime.timedelta(seconds=psutil.boot_time()))
with open('/proc/uptime', 'r') as f:
secs = float(f.readline().split()[0])
day = secs // (24 * 3600)
secs = secs % (24 * 3600)
hour = secs // 3600
secs %= 3600
minutes = secs // 60
secs %= 60
seconds = secs
payload = [
{
"days": day,
"hours": hour,
"minutes": minutes,
"seconds": seconds
}
]
return jsonify(payload)
app.run()