You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
from flask import Flask, jsonify
|
|
import random
|
|
import datetime
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
hostname = "Prijmeni_API"
|
|
|
|
def get_cpu_temp():
|
|
try:
|
|
temp = os.popen("cat /sys/class/thermal/thermal_zone0/temp").read()
|
|
return float(temp) / 1000.0
|
|
except Exception as e:
|
|
print (f"Chyba pri cteni teploty: {e}")
|
|
return None
|
|
|
|
|
|
@app.route("/api/teplota")
|
|
def teplota():
|
|
teplota_hodnota = get_cpu_temp()
|
|
cas = datetime.datetime.now().isoformat()
|
|
data = {
|
|
"hodnota":teplota_hodnota,
|
|
"cas":cas,
|
|
"hostname":hostname
|
|
}
|
|
return jsonify(data)
|
|
|
|
@app.route("/api/vlhkost")
|
|
def vlhkost():
|
|
vlhkost_hodnota = random.randint(2,95)
|
|
cas = datetime.datetime.now().isoformat()
|
|
data = {
|
|
"hodnota":vlhkost_hodnota,
|
|
"cas":cas,
|
|
"hostname":hostname
|
|
}
|
|
return jsonify(data)
|
|
|
|
@app.route("/api")
|
|
def all():
|
|
vlhkost_hodnota = random.randint(2,95)
|
|
teplota_hodnota = random.randint(10,30)
|
|
cas = datetime.datetime.now().isoformat()
|
|
data = {
|
|
"vlhkost":vlhkost_hodnota,
|
|
"teplota": teplota_hodnota,
|
|
"cas":cas,
|
|
"hostname":hostname
|
|
}
|
|
return jsonify(data)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0",port=5000)
|