feat: 🚧 Starting working on roomID
This commit is contained in:
parent
132d4ba4b5
commit
5907f5f786
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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
database.db
|
||||||
|
32
main.py
32
main.py
@ -3,39 +3,47 @@ import os
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask import Flask, request, render_template
|
from flask import Flask, request, render_template
|
||||||
from flask_bootstrap import Bootstrap5
|
from flask_bootstrap import Bootstrap5
|
||||||
|
|
||||||
from spotifySearch import searchSpotify
|
from spotifySearch import searchSpotify
|
||||||
|
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
bootstrap = Bootstrap5(app)
|
bootstrap = Bootstrap5(app)
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
database = sqlite3.connect("database.db")
|
||||||
def main_app():
|
|
||||||
|
@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
|
# handle the POST request
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
search = request.form.get('search')
|
search = request.form.get('search')
|
||||||
result = searchSpotify(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
|
# otherwise handle the GET request
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
@app.route('/add/<string:trackid>', methods=['GET'])
|
@app.route('/add/<string:roomid>/<string:trackid>', methods=['GET'])
|
||||||
def add_to_playlist(trackid):
|
def add_to_playlist(roomid, trackid):
|
||||||
|
print(roomid)
|
||||||
|
print(trackid)
|
||||||
if not os.getenv("n8n_webhook"):
|
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:
|
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':
|
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:
|
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:
|
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__':
|
if __name__ == '__main__':
|
||||||
# run app in debug mode on port 5000
|
|
||||||
app.run(debug=True, port="3000", host="0.0.0.0")
|
app.run(debug=True, port="3000", host="0.0.0.0")
|
@ -16,7 +16,7 @@
|
|||||||
icon: "{{ type }}",
|
icon: "{{ type }}",
|
||||||
confirmButtonText: "Add another track",
|
confirmButtonText: "Add another track",
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
window.location = "/";
|
window.location = "/search/{{ roomid }}";
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<h5 class="card-title"> {{ track[0] }} </h5>
|
<h5 class="card-title"> {{ track[0] }} </h5>
|
||||||
<p class="card-text">{{ track[1] }} - {{ track[2] }}</p>
|
<p class="card-text">{{ track[1] }} - {{ track[2] }}</p>
|
||||||
<audio controls><source src="{{ track[3] }}"></audio>
|
<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="hidden" name="track" value="{{ track[5] }}">
|
||||||
<input type="submit" value="Add to the playlist" class="btn btn-primary">
|
<input type="submit" value="Add to the playlist" class="btn btn-primary">
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user