1
Fork 0

idk random commit

This commit is contained in:
ventilaar 2021-10-26 09:15:23 +02:00
parent 87881aa466
commit a9fb02a161
3 changed files with 26 additions and 5 deletions

View File

@ -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

View File

@ -2,4 +2,5 @@
<master>
<!-- zet debug modes van flask aan met waarde True-->
<flask_debug>True</flask_debug>
<sqlite_location>database.db</sqlite_location>
</master>

View File

@ -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