aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sensor.py17
-rw-r--r--templates/show_entries.html18
2 files changed, 26 insertions, 9 deletions
diff --git a/sensor.py b/sensor.py
index 8d1e000..2e6c46c 100644
--- a/sensor.py
+++ b/sensor.py
@@ -44,13 +44,28 @@ def show_entries():
cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc')
entries = [dict(date=row[0], temperature=row[1], humidity=row[2], pressure=row[3]) for row in cur.fetchall()]
+ # datetimeline = pygal.DateTimeLine(
+ # x_label_rotation=30, truncate_label=-1,
+ # x_value_formatter=lambda dt: dt.strftime('%d, %b %Y %I:%M %p')
+ # )
+ # datetimeline.add("Temp F", [(row[0], row[1]) for row in cur.fetchall()])
+ # datetimeline.render_response()
+
+ # return render_template('show_entries.html', wgraph=datetimeline, weather=entries)
+ return render_template('show_entries.html', weather=entries)
+
+@app.route('/wgraph.svg')
+def weather_route():
+ cur = g.db.execute('SELECT date, temperature, humidity, pressure FROM weather ORDER BY id desc')
+
datetimeline = pygal.DateTimeLine(
x_label_rotation=30, truncate_label=-1,
x_value_formatter=lambda dt: dt.strftime('%d, %b %Y %I:%M %p')
)
datetimeline.add("Temp F", [(row[0], row[1]) for row in cur.fetchall()])
- return render_template('show_entries.html', wgraph=datetimeline, weather=entries)
+ return datetimeline.render_response()
+
# adding entries to database
@app.route('/data', methods=['POST'])
diff --git a/templates/show_entries.html b/templates/show_entries.html
index 1f18d68..5a9d989 100644
--- a/templates/show_entries.html
+++ b/templates/show_entries.html
@@ -1,11 +1,13 @@
{% extends "layout.html" %}
{% block body %}
- {{ wgraph.render()|safe }}
- <ul class=weather>
- {% for entry in weather %}
- <li><h2>{{ entry.date }}</h2>Temp: {{ entry.temperature }}, Humidity: {{ entry.humidity }}, Pressure: {{ entry.pressure }}
- {% else %}
- <li><em>No entries here so far</em>
- {% endfor %}
- </ul>
+ <figure>
+ <embed type="image/svg+xml" src="/wgraph.svg" />
+ </figure>
+ <ul class=weather>
+ {% for entry in weather %}
+ <li><h2>{{ entry.date }}</h2>Temp: {{ entry.temperature }}, Humidity: {{ entry.humidity }}, Pressure: {{ entry.pressure }}
+ {% else %}
+ <li><em>No entries here so far</em>
+ {% endfor %}
+ </ul>
{% endblock %}