diff --git a/Weekopdrachten/Week 3/Les 1/numers.py b/Weekopdrachten/Week 3/Les 1/numers.py index c9f28a7..a77e477 100644 --- a/Weekopdrachten/Week 3/Les 1/numers.py +++ b/Weekopdrachten/Week 3/Les 1/numers.py @@ -8,7 +8,7 @@ if os.path.exists('db.db'): con = sqlite3.connect('db.db') cur = con.cursor() -cur.execute(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='cijfers' ''') # tabel cijfers opvragen +cur.execute(''' SELECT name FROM sqlite_master WHERE type='table' AND name='hosts' ''') # tabel cijfers opvragen if cur.fetchone()[0] == 0: # als tabel niet bestaat cur.execute(''' CREATE TABLE cijfers (cijfer INTEGER) ''') # maak tabel aan met 1 kolom diff --git a/eindopdracht/monitoring/master/config.xml b/eindopdracht/monitoring/master/config.xml index 145bea8..cabb1d6 100644 --- a/eindopdracht/monitoring/master/config.xml +++ b/eindopdracht/monitoring/master/config.xml @@ -2,4 +2,5 @@ True + database.db \ No newline at end of file diff --git a/eindopdracht/monitoring/master/run.py b/eindopdracht/monitoring/master/run.py index b7051d7..82356da 100644 --- a/eindopdracht/monitoring/master/run.py +++ b/eindopdracht/monitoring/master/run.py @@ -1,29 +1,49 @@ from flask import Flask, render_template, request import sqlite3 as sql import xml.etree.ElementTree as ET -import json tree = ET.parse('config.xml') # parseer xml root = tree.getroot() # laad config items in python variabelen flask_debug = bool(root.find('flask_debug').text == 'True') # vind node in xml en als waarde 'True' is zet variablele op True +db_location = root.find('sqlite_location').text # initialiseer flask app = Flask(__name__) +# initialiseer sqlite +conn = sql.connect(db_location) + +def test_db(): + cur.execute(''' SELECT name FROM sqlite_master WHERE type='table' AND name='hosts' ''') + + if cur.fetchone()[0] == 0: # als tabel niet bestaat + print('tabel hosts bestaat niet, database wordt opnieuw aangemaakt') + + +def create_db_struct(): + cur.execute(''' CREATE TABLE cijfers (cijfer INTEGER) ''') # maak tabel aan met 1 kolom + con.commit() # commit alle wijzigingen + + +def insert_data(data): + """ + simpele functie om de gekregen dict te inserten in de sqlite database + """ + + + #dit is de document root @app.route('/') def index(): return root - - # POST DATA @app.route('/api/v1/host/post', methods=['POST']) def host_post(): data = request.get_json() # sla json data op in dict - return '{"status": 200}' + return '{"status": 200}' # return een json dict met waarde status 200