diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/.gitignore | 1 | ||||
-rw-r--r-- | python/README.md | 5 | ||||
-rw-r--r-- | python/database.py | 20 | ||||
-rw-r--r-- | python/main.py | 10 | ||||
-rw-r--r-- | python/routes.py | 24 |
5 files changed, 60 insertions, 0 deletions
diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..4a30035 --- /dev/null +++ b/python/README.md @@ -0,0 +1,5 @@ +[X] - Flask return json +[X] - Get parameters +[X] - Create database +[ ] - Interact with database +[ ] - diff --git a/python/database.py b/python/database.py new file mode 100644 index 0000000..5bc8b5f --- /dev/null +++ b/python/database.py @@ -0,0 +1,20 @@ +import mysql.connector + + +def getConnector(): + return mysql.connector.connect( + host="localhost", + user="root", + ) + + +def getCursor(connector): + return connector.cursor() + + +def runQuery(connector, query): + cursor = getCursor(connector) + cursor.execute(query) + result = cursor.fetchall() + cursor.close() + return result diff --git a/python/main.py b/python/main.py new file mode 100644 index 0000000..c778f8f --- /dev/null +++ b/python/main.py @@ -0,0 +1,10 @@ +import routes +import database + +connector = database.getConnector() +database.runQuery(connector, "SHOW DATABASES") + +app = routes.createApp() +routes.createRoutes(app, connector) + +app.run() diff --git a/python/routes.py b/python/routes.py new file mode 100644 index 0000000..a60584d --- /dev/null +++ b/python/routes.py @@ -0,0 +1,24 @@ +from flask import Flask, jsonify, request +import database + + +def createApp(): + return Flask(__name__) + + +def createRoutes(app, connector): + @app.route("/", methods=['GET']) + def hello_world(): + arg1 = request.args.get('arg1') + arg2 = request.args.get('arg2') + return jsonify({'arg1': arg1, + 'arg2': arg2}) + + @app.route("/db", methods=['GET']) + def database_hello(): + return jsonify( + database.runQuery( + connector, + "SHOW DATABASES" + ) + ) |