Skip to content
Snippets Groups Projects
Commit 5f6c442b authored by Stephen Farry's avatar Stephen Farry
Browse files

Merge branch 'master' of ssh://gitlab.cern.ch:7999/hev-sw/hev-sw

parents 1b4b9ada c7bb8752
Branches
No related merge requests found
......@@ -17,6 +17,8 @@ from datetime import datetime
import logging
logging.basicConfig(level=logging.WARNING, format='%(asctime)s - %(levelname)s - %(message)s')
import io
import csv
import sys
import argparse
import sqlite3
......@@ -440,6 +442,41 @@ def send_ack():
return ('', 204)
@WEBAPP.route("/downloadCSV", methods=['POST'])
def downloadCSV():
sqlSelect = "SELECT * FROM hev_monitor_data; "
timestr = time.strftime("%Y%m%d-%H%M%S")
fileName= 'export_'+timestr+'.csv'
try:
conn = sqlite3.connect(SQLITE_FILE, check_same_thread = False, uri = True)
cursor = conn.cursor()
si = io.StringIO()
cw = csv.writer(si, dialect='excel', delimiter=',')
for row in cursor.execute(sqlSelect):
cw.writerow(row)
#results = cursor.fetchall()
#print(results)
# Extract the table headers.
#headers = [i[0] for i in cursor.description]
#cw.writerows(headers)
#csv.writer.writerow (results)
output = make_response(si.getvalue())
output.headers["Content-Disposition"] = "attachment; filename="+fileName
output.headers["Content-type"] = "text/csv"
output.headers["charset"]='utf-8-sig'
print("Data export successful.")
except sqlite3.Error as err:
conn.close()
raise Exception("sqlite3 error. CSV export failed: {}".format(str(err)))
finally:
conn.close()
return output
@WEBAPP.route('/live-data', methods=['GET'])
def live_data():
......
......@@ -87,15 +87,22 @@
</div></a>
</div>
</div>
<form action="{{ url_for('send_cmd') }}" method="post">
<div class = "controls py-1 ml-auto mr-auto">
<input type="submit" name="start" value="START" onclick="cmdNotification(this.value)" class="lockable sb-nav-button py-1 mb-1" disabled></input>
<input type="submit" name="stop" value="STOP" onclick="cmdNotification(this.value)" class="lockable sb-nav-button py-1 mb-1" disabled></input>
</div>
</form>
<!-- <input type="submit" name="reset" value="RESET" onclick="cmdNotification(this.value)" class="sb-nav-button py-1 mb-1"></input> -->
<form action="{{ url_for('downloadCSV') }}" method="post">
<div class = "controls py-1 ml-auto mr-auto">
<input type="submit" name="export" value="EXPORT" onclick="cmdNotification(this.value)" class="lockable sb-nav-button py-1 mb-1" disabled></input>
</div>
</form>
</div>
</nav>
</div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment