import requests
import logging
from flask import Flask
from flask import render_template

DISTANCE_URL = "http://192.168.115.23/d"

def get_distance():
    response = requests.get(DISTANCE_URL)
    try:
        return response.json()["distance"]
    except Exception as e:
        logging.error(e)
        return 0

app = Flask(__name__)

@app.route("/")
def main():
    return render_template("index.html")

@app.route("/d")
def distance():
    return {"distance": get_distance()}
    
@app.route("/n")
def neo():
    return render_template("neo.html")

@app.route("/p")
def progbar():
    return render_template("progbar.html")
