2 changed files with 57 additions and 0 deletions
@ -0,0 +1,56 @@ |
|||||
|
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) |
Loading…
Reference in new issue