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.
40 lines
986 B
40 lines
986 B
from flask import Flask, jsonify, render_template
|
|
import random
|
|
|
|
#vytvoření Flask aplikace
|
|
app = Flask(__name__)
|
|
|
|
def generuj_data():
|
|
teplota = random.randint(20,28)
|
|
vlhkost = random.randint(40,80)
|
|
led_stav = bool(random.randint(0,1))
|
|
return {
|
|
"nazev": "hodnota",
|
|
"teplota": teplota,
|
|
"vlhkost": vlhkost,
|
|
"led_stav": led_stav
|
|
}
|
|
|
|
@app.route("/")
|
|
def index():
|
|
#vytvoříme si složku templates a vložíme do ní index.html
|
|
return render_template("index.html")
|
|
|
|
@app.route("/api/data",methods=["GET"])
|
|
def get_data():
|
|
data = generuj_data()
|
|
return jsonify(data)
|
|
|
|
@app.route("/api/teplota",methods=["GET"])
|
|
def get_teplota():
|
|
data = generuj_data()
|
|
return jsonify({"teplota":data["teplota"]})
|
|
|
|
@app.route("/api/vlhkost",methods=["GET"])
|
|
def get_vlhkost():
|
|
data = generuj_data()
|
|
return jsonify({"vlhkost":data["vlhkost"]})
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True, port=8000)
|
|
|
|
|