From aaed0c19e04c47b54a812b003f7645e26a9f3201 Mon Sep 17 00:00:00 2001 From: Hubert Dwornik Date: Sat, 11 May 2024 14:21:32 +0200 Subject: [PATCH] prototype connector --- ai_front_connector/frontend_AI_connector.py | 44 +++++++++++++++++++++ ai_front_connector/mock_db/db.json | 1 + ai_front_connector/requirements.txt | 2 + 3 files changed, 47 insertions(+) create mode 100644 ai_front_connector/frontend_AI_connector.py create mode 100644 ai_front_connector/mock_db/db.json create mode 100644 ai_front_connector/requirements.txt diff --git a/ai_front_connector/frontend_AI_connector.py b/ai_front_connector/frontend_AI_connector.py new file mode 100644 index 00000000..ad81eb5b --- /dev/null +++ b/ai_front_connector/frontend_AI_connector.py @@ -0,0 +1,44 @@ +from flask import Flask, request, jsonify +import tinydb + +files = [] + +DB_PATH = "ai_front_connector/mock_db/db.json" + +app = Flask(__name__) +db_connector = None + +@app.route("/", methods=["GET"]) +def hello(): + return jsonify({"response": "Hello there"}), 200 + +@app.route("/api/v3/get//", methods=["POST"]) +def access_user(oauth_ID, username): + print(oauth_ID, username) + return jsonify({"status": "success"}), 200 + +@app.route("/api/v3/add//", methods=["POST"]) +def add_user(oauth_ID, username): + res = db_connector.search(tinydb.where('username') == username) + + if len(res): + return jsonify({"status": "User already exists"}), 500 + + db_connector.insert({"ID": oauth_ID, "username": username}) + return jsonify({"status": "success"}), 200 + + +#idk, czy zrobimy to w ten sposób, ale na wszelki w, route może pozostać, IG +@app.route("/api/v3/ai/", methods=["GET"]) +def get_recommendations(oauth_ID): + #request od frontu na rekomendacje + #wysyłanie requestu do AI API o rekomendacje dla usera + #przesłanie danych do + return jsonify({"movies": ["3", "Wiedźmin 3", "Najlepszy."]}), 200 + +if __name__ == "__main__": + db_connector = tinydb.TinyDB(DB_PATH) + + app.run(port=8080, debug=True) + + diff --git a/ai_front_connector/mock_db/db.json b/ai_front_connector/mock_db/db.json new file mode 100644 index 00000000..8201b8ef --- /dev/null +++ b/ai_front_connector/mock_db/db.json @@ -0,0 +1 @@ +{"_default": {"1": {"ID": "123123", "username": "ziom69"}, "2": {"ID": "123123", "username": "ziom66"}}} \ No newline at end of file diff --git a/ai_front_connector/requirements.txt b/ai_front_connector/requirements.txt new file mode 100644 index 00000000..253b96c5 --- /dev/null +++ b/ai_front_connector/requirements.txt @@ -0,0 +1,2 @@ +tinydb==4.8.0 +flask==3.0.3 \ No newline at end of file