title: update a variable in a web app with flask
body: <p>I have an arduino program and set-up which detects the number of cars from a parking lot. The number of cars is printed on the serial every time when the sensor detects a car in front of the barrier.
  I want to print the number of cars from the parking lot into a small web app. I use Tera Term to scan my serial bus and put the output data into a file text ( data.txt) . Then i use python to read the value from that text file and render it into a HTML page on a web app.</p>
  
  <p>Here is the python code : </p>
  
  <pre><code>from flask import Flask, render_template
  import logging
  import requests
  
  
  # Initialize the Flask application
  app = Flask(__name__)
  
  # Define a route for the default URL, which loads the form
  @app.route("/")
  def form():
   with open('date.txt') as f:
       data = []
       lines = f.read().splitlines()
       data.append(lines)
   for i in data:
       return render_template('index.html', variable=data)
  
  
  if __name__ == "__main__":
   app.run()
  </code></pre>
  
  <p>here is index.html</p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Arduino Project&lt;/title&gt;
      &lt;style&gt;
          body{
              background: antiquewhite;
          }
  h1 {color:red;
  text-align: center;}
  h2 {color:blue;
     text-align: center;}
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt; - Arduino - &lt;/h1&gt;
  &lt;h2&gt; Number of cars in the parking place: {{ variable }}&lt;br&gt;&lt;/h2&gt;
  &lt;script&gt; setTimeout(function(){
     window.location.reload(1);
  }, 5000);
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>It works fine, but i want to have only a variable which updates every 5 seconds,when the page is refreshed.I dont want to see all values from the date.txt,just the last one.</p>
  
  <p>This is how my web app looks like with this code until now :
  (ignore the error message)
  <a href="https://i.stack.imgur.com/zOAo8.png" rel="nofollow noreferrer">enter image description here</a></p>