thunix_api/thunix_api.py

52 lines
822 B
Python
Raw Normal View History

2020-01-22 18:29:15 +00:00
# thunix_api.py
import flask
from flask import Flask, request, jsonify
2020-01-22 19:28:44 +00:00
import psutil, datetime
2020-01-22 18:29:15 +00:00
app = Flask(__name__)
2020-01-22 19:28:44 +00:00
2020-01-22 18:29:15 +00:00
# No endpoint selected
@app.route("/")
def home():
return "The Thunix API. Please see https://wiki.thunix.net/wiki/api for more information."
app.run()
2020-01-22 19:28:44 +00:00
2020-01-22 18:29:15 +00:00
# ip_info
@app.route("/ip_info")
def ip_info():
return "IP Info"
app.run()
2020-01-22 19:28:44 +00:00
2020-01-22 18:29:15 +00:00
# uptime
@app.route("/uptime")
def uptime():
2020-01-22 19:28:44 +00:00
return str(datetime.timedelta(seconds=psutil.boot_time()))
2020-01-22 18:29:15 +00:00
app.run()
2020-01-22 19:28:44 +00:00
2020-01-22 18:29:15 +00:00
# teapot
@app.route("/teapot")
def teapot():
2020-01-22 19:28:44 +00:00
teapots = [
{
"tea": "available",
"height": "short",
"width": "stout"
}
]
return jsonify(teapots)
app.run()
2020-01-22 18:29:15 +00:00
# main loop
2020-01-22 19:28:44 +00:00
if __name__ == "__main__": # on running python app.py
app.run() # run the flask app