feat: 🚧 Starting working on Spotify authentification for playlist creation
This commit is contained in:
parent
f3d606ee7d
commit
708c8beac6
18
main.py
18
main.py
@ -3,8 +3,8 @@ import os
|
||||
from flask import Flask, request, render_template
|
||||
from flask_bootstrap import Bootstrap5
|
||||
from utils.spotifyAPI import searchSpotify
|
||||
|
||||
import sqlite3
|
||||
from random import randint
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
@ -24,11 +24,23 @@ def main():
|
||||
if roomSearch:
|
||||
return render_template("index.html", response="We found your collaborative playlist", comment="It is a great news, click the button below to access it.", type="success", roomid=roomid)
|
||||
else:
|
||||
cursor.execute("INSERT INTO rooms (roomid, spotify_id, playlist_name) VALUES (?, ?, ?)", (roomid, "test", "test"))
|
||||
database.commit()
|
||||
return render_template("index.html", response="We could not find your collaborative playlist", comment="Please check the room id and try again or create one.", type="error", roomid=roomid)
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route('/create', methods=["POST"])
|
||||
def create_playlist():
|
||||
playlistName = request.form.get('roomName')
|
||||
if not playlistName:
|
||||
return render_template("create.html", response="Invalid playlist name", comment="Please provide a valid playlist name", type="error")
|
||||
playlistID = "test"
|
||||
# check if the room id already exists
|
||||
roomid = randint(10000000, 99999999)
|
||||
while cursor.execute("SELECT * FROM rooms WHERE roomid = ?", (roomid,)).fetchone():
|
||||
roomid = randint(10000000, 99999999)
|
||||
cursor.execute("INSERT INTO rooms (roomid, spotify_id, playlist_name) VALUES (?, ?, ?)", (roomid, playlistID, playlistName))
|
||||
database.commit()
|
||||
return render_template("create.html", response="Playlist created successfully", comment="Enjoy the night \U0001f57a", type="success", roomid=roomid)
|
||||
|
||||
@app.route('/search/<string:roomid>', methods=['GET', 'POST'])
|
||||
def main_app(roomid):
|
||||
if len(roomid) != 8 or not cursor.execute("SELECT * FROM rooms WHERE roomid = ?", (roomid,)).fetchone():
|
||||
|
34
templates/create.html
Normal file
34
templates/create.html
Normal file
@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Fête de la musique</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
{{ bootstrap.load_css() }}
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<script>
|
||||
if ("{{type}}" === "error") {
|
||||
Swal.fire({
|
||||
title: "{{ response }}",
|
||||
text: "{{ comment }}",
|
||||
icon: "{{ type }}",
|
||||
confirmButtonText: "Try again",
|
||||
}).then(function() {
|
||||
window.location = "/";
|
||||
})
|
||||
}
|
||||
Swal.fire({
|
||||
title:"{{ response }}",
|
||||
text: "{{ comment }}",
|
||||
icon: "{{ type }}",
|
||||
confirmButtonText: "Add some music!",
|
||||
}).then(function() {
|
||||
window.location = "/search/{{ roomid }}";
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
@ -24,3 +24,12 @@ def searchSpotify(spotifySearch, limit=10):
|
||||
def createPlaylist(playlistName):
|
||||
#TODO: Implement this function
|
||||
pass
|
||||
|
||||
def spotifyLogin():
|
||||
"""
|
||||
This function is used to login to spotify to get the user token
|
||||
:return: user token
|
||||
"""
|
||||
credentials = spotipy.oauth2.SpotifyClientCredentials(client_id=os.getenv("client_id"), client_secret=os.getenv("client_secret"))
|
||||
spotify_token = credentials.get_access_token()
|
||||
return spotify_token
|
Loading…
x
Reference in New Issue
Block a user