feat/room-id #2
2
.gitignore
vendored
2
.gitignore
vendored
@ -267,3 +267,5 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
|
||||
database.db
|
||||
|
32
main.py
32
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/<string:roomid>', 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/<string:trackid>', methods=['GET'])
|
||||
def add_to_playlist(trackid):
|
||||
@app.route('/add/<string:roomid>/<string:trackid>', 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")
|
@ -16,7 +16,7 @@
|
||||
icon: "{{ type }}",
|
||||
confirmButtonText: "Add another track",
|
||||
}).then(function() {
|
||||
window.location = "/";
|
||||
window.location = "/search/{{ roomid }}";
|
||||
})
|
||||
|
||||
</script>
|
||||
|
@ -35,7 +35,7 @@
|
||||
<h5 class="card-title"> {{ track[0] }} </h5>
|
||||
<p class="card-text">{{ track[1] }} - {{ track[2] }}</p>
|
||||
<audio controls><source src="{{ track[3] }}"></audio>
|
||||
<form method="GET" action="/add/{{track[5]}}">
|
||||
<form method="GET" action="/add/{{roomid}}/{{track[5]}}">
|
||||
<input type="hidden" name="track" value="{{ track[5] }}">
|
||||
<input type="submit" value="Add to the playlist" class="btn btn-primary">
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user