idk random commit
This commit is contained in:
parent
87881aa466
commit
a9fb02a161
|
@ -8,7 +8,7 @@ if os.path.exists('db.db'):
|
||||||
con = sqlite3.connect('db.db')
|
con = sqlite3.connect('db.db')
|
||||||
cur = con.cursor()
|
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
|
if cur.fetchone()[0] == 0: # als tabel niet bestaat
|
||||||
cur.execute(''' CREATE TABLE cijfers (cijfer INTEGER) ''') # maak tabel aan met 1 kolom
|
cur.execute(''' CREATE TABLE cijfers (cijfer INTEGER) ''') # maak tabel aan met 1 kolom
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
<master>
|
<master>
|
||||||
<!-- zet debug modes van flask aan met waarde True-->
|
<!-- zet debug modes van flask aan met waarde True-->
|
||||||
<flask_debug>True</flask_debug>
|
<flask_debug>True</flask_debug>
|
||||||
|
<sqlite_location>database.db</sqlite_location>
|
||||||
</master>
|
</master>
|
|
@ -1,29 +1,49 @@
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import json
|
|
||||||
|
|
||||||
tree = ET.parse('config.xml') # parseer xml
|
tree = ET.parse('config.xml') # parseer xml
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
# laad config items in python variabelen
|
# 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
|
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
|
# initialiseer flask
|
||||||
app = Flask(__name__)
|
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
|
#dit is de document root
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# POST DATA
|
# POST DATA
|
||||||
@app.route('/api/v1/host/post', methods=['POST'])
|
@app.route('/api/v1/host/post', methods=['POST'])
|
||||||
def host_post():
|
def host_post():
|
||||||
data = request.get_json() # sla json data op in dict
|
data = request.get_json() # sla json data op in dict
|
||||||
return '{"status": 200}'
|
return '{"status": 200}' # return een json dict met waarde status 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue