From 5907f5f7862f3abe641086ac5534687cf7476a25 Mon Sep 17 00:00:00 2001 From: Louis Gallet Date: Sun, 30 Jun 2024 22:55:01 +0200 Subject: [PATCH] feat: :construction: Starting working on roomID --- .gitignore | 2 ++ main.py | 32 ++++++++++++++++++++------------ templates/add.html | 2 +- templates/found.html | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 4a5762c..09b72b2 100644 --- a/.gitignore +++ b/.gitignore @@ -267,3 +267,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +database.db diff --git a/main.py b/main.py index c9753ec..22381bd 100644 --- a/main.py +++ b/main.py @@ -3,39 +3,47 @@ import os from dotenv import load_dotenv from flask import Flask, request, render_template from flask_bootstrap import Bootstrap5 - from spotifySearch import searchSpotify +import sqlite3 + app = Flask(__name__) bootstrap = Bootstrap5(app) -@app.route('/', methods=['GET', 'POST']) -def main_app(): +database = sqlite3.connect("database.db") + +@app.route("/", methods=['GET']) +def main(): + return "Hello, World!" + +@app.route('/search/', methods=['GET', 'POST']) +def main_app(roomid): # handle the POST request if request.method == 'POST': search = request.form.get('search') result = searchSpotify(search) - return render_template("found.html", query=search, tracks=result) + return render_template("found.html", query=search, tracks=result, roomid=roomid) # otherwise handle the GET request return render_template("index.html") -@app.route('/add/', methods=['GET']) -def add_to_playlist(trackid): +@app.route('/add//', methods=['GET']) +def add_to_playlist(roomid, trackid): + print(roomid) + print(trackid) if not os.getenv("n8n_webhook"): - return render_template("add.html", response="No n8n webhook provided", comment="Please provide a n8n webhook in the .env file", type="error") + return render_template("add.html", response="No n8n webhook provided", comment="Please provide a n8n webhook in the .env file", type="error", roomid=roomid) try: - data = requests.get(os.getenv("n8n_webhook") + "/" + trackid) + data = requests.get(os.getenv("n8n_webhook") + "/" + roomid + "/" + trackid) if data.json()['message'] == 'Workflow was started': - return render_template("add.html", response="Track added to playlist successfully", comment="Enjoy the night \U0001f57a", type="success") + return render_template("add.html", response="Track added to playlist successfully", comment="Enjoy the night \U0001f57a", type="success", roomid=roomid) else: - return render_template("add.html", response='Invalid response from server', comment=data.text, type="error") + return render_template("add.html", response='Invalid response from server', comment=data.text, type="error", roomid=roomid) except requests.exceptions.RequestException as e: - return render_template("add.html", response='Request failed', comment=e, type="error") + return render_template("add.html", response='Request failed', comment=e, type="error", roomid=roomid) if __name__ == '__main__': - # run app in debug mode on port 5000 app.run(debug=True, port="3000", host="0.0.0.0") \ No newline at end of file diff --git a/templates/add.html b/templates/add.html index fd6bfa0..90abaf0 100644 --- a/templates/add.html +++ b/templates/add.html @@ -16,7 +16,7 @@ icon: "{{ type }}", confirmButtonText: "Add another track", }).then(function() { - window.location = "/"; + window.location = "/search/{{ roomid }}"; }) diff --git a/templates/found.html b/templates/found.html index 438c683..9105705 100644 --- a/templates/found.html +++ b/templates/found.html @@ -35,7 +35,7 @@
{{ track[0] }}

{{ track[1] }} - {{ track[2] }}

-
+