feat: 🚧 Starting working on spotify auth + create QR code for easy sharing

This commit is contained in:
2024-07-01 00:42:46 +02:00
parent 708c8beac6
commit 9a1e02c90a
4 changed files with 51 additions and 12 deletions

18
utils/generateQRCode.py Normal file
View File

@ -0,0 +1,18 @@
import qrcode
from io import BytesIO
import base64
def generateQRCode(url: str, img_name: str = 'QR_Code.png') -> str:
"""
This function generates a QR code from a given URL and saves it as an image file
:param url: URL to generate QR code from
:param img_name: Name of the image file
:return: base64 encoded image
"""
code = qrcode.QRCode(version=1, box_size=10, border=4)
code.add_data(url)
code.make(fit=True)
img = code.make_image(fill_color="black", back_color="white")
buffered = BytesIO()
img.save(buffered)
img_str = base64.b64encode(buffered.getvalue()).decode()
return img_str

View File

@ -1,7 +1,8 @@
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from spotipy.oauth2 import SpotifyClientCredentials, SpotifyOAuth
import os
from dotenv import load_dotenv
from flask import url_for
load_dotenv()
@ -25,11 +26,14 @@ def createPlaylist(playlistName):
#TODO: Implement this function
pass
def spotifyLogin():
def create_spotify_oauth():
"""
This function is used to login to spotify to get the user token
:return: user token
This function creates a Spotify OAuth object
:return: SpotifyOAuth object
"""
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
return SpotifyOAuth(
client_id=os.getenv("client_id"),
client_secret=os.getenv("client_secret"),
redirect_uri=url_for('callback', _external=True),
scope='playlist-modify-public'
)