diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..18e5dee88df4de6a8bb32ed0a961f5c1c5897880 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM debian:10.4 +COPY app /app +RUN apt-get update && apt-get install +RUN apt-get install python3-pip -y +RUN pip3 install Flask +RUN pip3 install jinja2 +RUN pip3 install pyyaml +CMD python3 /app/sqlite.py, python3 /app/run.py diff --git a/Website/Dockerfile b/Website/Dockerfile deleted file mode 100644 index 04400b5ba21e78c8581a1ac71873f3390893efa2..0000000000000000000000000000000000000000 --- a/Website/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.7.3 -RUN pip3 install Flask -RUN pip3 install jinja2 -RUN pip3 install pyyaml -COPY . /website -CMD python3 sqlite1.py, python3 run.py diff --git a/Website/run.py b/Website/run.py deleted file mode 100644 index d3c169dba3658b1f79940b12817b988a5b8b41e6..0000000000000000000000000000000000000000 --- a/Website/run.py +++ /dev/null @@ -1,51 +0,0 @@ -import sqlite3 -from flask import Flask, render_template -myapp = Flask(__name__) - -dic = {"nname" : "Ford", "vname" : "Harrison", "gebjahr" : 1942} - -def ausgabe(): - connect = sqlite3.connect("/website/test.db") - cursor = connect.cursor() - cursor.execute("SELECT COUNT(username) AS username FROM benutzer") - #anzahl = int(str(cursor.fetchone())) - a_user = [] - for i in range(0,4): - cursor.execute("SELECT username FROM benutzer WHERE b_nr ="+ str(i)) - temp_name = cursor.fetchone() - a_user.append(temp_name) - print(type(a_user)) - return a_user - - user = cursor.fetchall() - -def attribute(): - connect = sqlite3.connect("/website/test.db") - cursor = connect.cursor() - cursor.execute("SELECT username FROM benutzer") - user = cursor.fetchall() - print(type(user)) - username = [] - print(type(username)) - for person in user: - username.append(person) - i = 1 - return username - -@myapp.route("/users") -def templ_test(): - return render_template('users.html', mydict = dic, list=[3,6,2,"drei",4,5], user_list = attribute(), userarray = ausgabe()) - -@myapp.route("/users/('mduscha',)") -def getduscha(): - connect = sqlite3.connect("/website/test.db") - cursor = connect.cursor() - cursor.execute("SELECT * FROM benutzer WHERE username = 'mduscha'") - mduscha = cursor.fetchall() - return str(mduscha) - -if __name__ == '__main__': - #print(dic) - #ausgabe() - #print(attribute()) - myapp.run(host = "0.0.0.0", debug = True) \ No newline at end of file diff --git a/Website/sqlite1.py b/Website/sqlite1.py deleted file mode 100644 index d811ef047ba6866800340786d01fb26f6292471c..0000000000000000000000000000000000000000 --- a/Website/sqlite1.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python3 -import sqlite3 -import yaml - -connection = sqlite3.connect("test.db") -cursor = connection.cursor() - -#Ab hier: ABSTRAKTION -cursor.execute("DROP TABLE IF EXISTS benutzer;") -sql_command = """ -CREATE TABLE benutzer ( -b_nr INTEGER PRIMARY KEY, -vname VARCHAR(40), -nname VARCHAR(40), -username VARCHAR(40), -aktiv INTEGER, -mail VARCHAR(60), -beitritt DATE -); """ -cursor.execute(sql_command) - -#Benutzer aus YAML-Datei lesen und in die Tabelle einfügen -with open('users.yaml') as f: - global users - users = yaml.safe_load(f) - -#print(users) - -def addPerson(vname, nname, username, aktiv, mail, beitritt): - cursor.execute("INSERT INTO benutzer(vname, nname, username, aktiv, mail, beitritt) VALUES (:vn, :nn, :un, :akt, :mail, :bei)", {'vn': vname, 'nn': nname, 'un': username, 'akt': aktiv, 'mail': mail, 'bei': beitritt}) - -for x in range (0, 3): - addPerson(users[x] ['vname'], users[x] ['nname'], users[x] ['username'], users[x] ['aktiv'], users[x] ['mail'], users[x] ['beitritt']) -connection.commit() -connection.close() - -#sql_command = """ -#SELECT * -#FROM benutzer; -#""" -#cursor.execute(sql_command) -#print(cursor.fetchall()) \ No newline at end of file diff --git a/Website/templates/users.html b/Website/templates/users.html deleted file mode 100644 index e9c9f6cf7aeb4f554248ba474a2e035aeedd27ec..0000000000000000000000000000000000000000 --- a/Website/templates/users.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Meine Seite - - - {{string_aus}} - - \ No newline at end of file diff --git a/Website/users.yaml b/Website/users.yaml deleted file mode 100644 index 0f872515b3328de13f7b10d0ef674b9ae579cb77..0000000000000000000000000000000000000000 --- a/Website/users.yaml +++ /dev/null @@ -1,24 +0,0 @@ -- - b_nr: 0 - vname: Miriam - nname: Duscha - username: mduscha - aktiv: 1 - mail: mduscha@mail.de - beitritt: 2020-07-20 -- - b_nr: 1 - vname: Fabian - nname: Wandt - username: fwandt - aktiv: 1 - mail: fwandt@mail.de - beitritt: 2020-07-20 -- - b_nr: 2 - vname: Maria - nname: Dalton-Beatle - username: mariadb - aktiv: 0 - mail: mariadb@mail.de - beitritt: 2017-04-20 \ No newline at end of file diff --git a/app/__pycache__/flask.cpython-37.pyc b/app/__pycache__/flask.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0aa021d81f60585beeb4b15db29d6f4b7f32b5a9 Binary files /dev/null and b/app/__pycache__/flask.cpython-37.pyc differ diff --git a/app/flask_server.py b/app/flask_server.py new file mode 100644 index 0000000000000000000000000000000000000000..5b7ca803c800b5c12e1aa5f414dfb95ee646c413 --- /dev/null +++ b/app/flask_server.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 +from flask import Flask, render_template +import sqlite3 + +DATABASE = "test.db" +app = Flask(__name__) +name = str(app.route) + +def all_user(): + connection = sqlite3.connect("test.db") + cursor = connection.cursor() + connection.row_factory = sqlite3.Row + cursor.execute("SELECT username FROM benutzer") + usernames = cursor.fetchall() + return usernames + +def one_user(name): + connection = sqlite3.connect("test.db") + cursor = connection.cursor() + connection.row_factory = sqlite3.Row + cursor.execute("SELECT * FROM benutzer WHERE vname = " + str(name)) + username = cursor.fetchone() + return username + +@app.route('/user') +def aufruf(): + return render_template("user.html", user_nms = all_user()) + +if __name__ == '__main__': + app.run(host = "0.0.0.0", debug = True) \ No newline at end of file diff --git a/app/run.py b/app/run.py new file mode 100644 index 0000000000000000000000000000000000000000..0cf31afd108e2d49f072f8eb9fa4ed89fbd2fde2 --- /dev/null +++ b/app/run.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +from flask import Flask, render_template, request +import sqlite3 + +databse = "test.db" +app = Flask(__name__) +name = str(app.route) + + +def all_user(): + connection = sqlite3.connect("test.db") + cursor = connection.cursor() + connection.row_factory = sqlite3.Row + cursor.execute("SELECT username FROM benutzer;") + all_i = cursor.fetchall() + return all_i + +def one_user(name): + connection = sqlite3.connect("test.db") + cursor = connection.cursor() + connection.row_factory = sqlite3.Row + cursor.execute("SELECT * FROM benutzer WHERE username = '" + name + "';") + user_data = cursor.fetchone() + return user_data + +def get_name(name): + connection = sqlite3.connect("test.db") + cursor = connection.cursor() + connection.row_factory = sqlite3.Row + cursor.execute("SELECT username FROM benutzer WHERE username = '" + name + "';") + user_id = cursor.fetchone() + return user_id + +@app.route('/user', methods=['GET','POST']) +def username_ausgabe(): + return render_template("users.html", all_ids = all_user()) + +@app.route('/user/', methods=['GET','POST']) +def user_ausgabe(username): + return render_template("user.html", user = one_user(username), name=get_name(username)) + +if __name__ == '__main__': + app.run(host = "0.0.0.0", debug = True) \ No newline at end of file diff --git a/app/sqlite.py b/app/sqlite.py new file mode 100644 index 0000000000000000000000000000000000000000..c53753c51a55099f6346732a6274f0acfa3842fb --- /dev/null +++ b/app/sqlite.py @@ -0,0 +1,50 @@ +#!/usr/bin/python3 +import sqlite3 +import yaml + +#Einlesen der User aus der yaml-Datei users +with open('users.yaml') as yaml_file: + users = yaml.load(yaml_file) + +#Aufbauen einer Verbindung zur Datenbank test +connection = sqlite3.connect("test.db") +cursor = connection.cursor() + +#Löscht Tabelle Benutzer, wenn sie exisitert +drop_benutzer = "DROP TABLE IF EXISTS benutzer; " +cursor.execute(drop_benutzer) + +#Erstellt Tabelle Benutzer +create_benutzer = """ +CREATE TABLE benutzer ( +user_id INTEGER PRIMARY KEY, +vname VARCHAR(20), +nname VARCHAR(20), +username VARCHAR(20), +joining DATE, +aktiv VCHAR(4) +);""" +cursor.execute(create_benutzer) + +#Methode, um User-Datensätze in die Tabelle einzutragen +def insert(user_id, vname, nname, username, joining, aktiv): + cursor.execute("INSERT INTO benutzer(user_id, vname, nname, username, joining, aktiv) VALUES (:user_id, :vname, :nname, :username, :joining, :aktiv)" , {'user_id' : user_id, 'vname' : vname, 'nname' : nname, 'username' : username, 'joining' :joining, 'aktiv' : aktiv}) + +#Eintragen der vorhandenen user (aus der Yaml-Datei) in die Tabelle +for p in users: + insert(p['user_id'], p['vname'], p['nname'], p['username'], p['joining'], p['aktiv']) + +connection.commit() +connection.close() + + + + + + + + + + + + diff --git a/app/templates/template.html b/app/templates/template.html new file mode 100644 index 0000000000000000000000000000000000000000..f378d64b446e934526d2779ed2e678ad8b0b0117 --- /dev/null +++ b/app/templates/template.html @@ -0,0 +1,16 @@ + + + + + Title + + +
+ {{my_string}} +
+ +
+ {{my_list}} +
+ + \ No newline at end of file diff --git a/app/templates/user.html b/app/templates/user.html new file mode 100644 index 0000000000000000000000000000000000000000..591ff4d720794d77dfa4ee33fbcab96758a0f538 --- /dev/null +++ b/app/templates/user.html @@ -0,0 +1,27 @@ + + + + Username: {% for n in name %} {{n}} {% endfor %} + + + + + + + + + + + + + {% for attribute in user %} + + {% endfor %} + +
User_idNachnameVornameNutzernameBeigetreten amAktiver Nutzer
{{attribute}}
+
+
+ Startseite +
+ + \ No newline at end of file diff --git a/app/templates/users.html b/app/templates/users.html new file mode 100644 index 0000000000000000000000000000000000000000..692d1df9ee385f0524e1314f5567dc6d9bdca787 --- /dev/null +++ b/app/templates/users.html @@ -0,0 +1,17 @@ + + + + + Startseite + + + + User: + {% for person in all_ids %} + {% for id in person %} + + {% endfor %} + {% endfor %} +
{{id}}
+ + \ No newline at end of file diff --git a/Website/test.db b/app/test.db similarity index 63% rename from Website/test.db rename to app/test.db index 25d729937d3501bc138105ac117421a32799f787..1652dc69d4719708dde7497e0b50dae8b6bde9be 100644 Binary files a/Website/test.db and b/app/test.db differ diff --git a/app/users.yaml b/app/users.yaml new file mode 100644 index 0000000000000000000000000000000000000000..191672bf767f22e5a9f19b1637110028f3f211fc --- /dev/null +++ b/app/users.yaml @@ -0,0 +1,28 @@ +- + user_id: 1 + vname: Miriam + nname: Duscha + username: dramalama + joining: 20.03.1990 + aktiv: ja +- + user_id: 2 + vname: Fabian + nname: Wandt + username: scriptkiddie + joining: 13.03.2005 + aktiv: nein +- + user_id: 3 + vname: Chris + nname: Linnemann + username: erdbeere + joining: 15.06.2000 + aktiv: ja +- + user_id: 4 + vname: Kilian + nname: Hassatzky + username: cptkiwi + joining: 15.06.2000 + aktiv: ja \ No newline at end of file diff --git a/templates/users.html b/templates/users.html deleted file mode 100644 index 8075042cef0136c505b9426e5303099801dd2464..0000000000000000000000000000000000000000 --- a/templates/users.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Meine Seite - - -
- Dictionairy: - -
- User: -
- -
- Test: -
- {{userarray}} - - \ No newline at end of file