Adds object creation from spotify

Now includes functions to convert json to track, artist and album
This commit is contained in:
2024-02-06 01:13:57 +01:00
parent 727cfc9a14
commit e7ee92868f
4 changed files with 87 additions and 9 deletions
+14 -4
View File
@@ -4,8 +4,18 @@ from django.http import HttpResponse
from . import models
from . import spotify
spt = spotify.Spotify()
class TrackView(View):
def get(self, request):
return HttpResponse("Hello world!")
def post(self, request):
return HttpResponse("Bye world")
def get(self, request, spotify_id):
# TODO: Dit is eigenlijk wat moet gebeuren op post
try:
track = models.Track.objects.get(pk=spotify_id)
except models.Track.DoesNotExist:
data = spt.get_song_info(spotify_id)
track = models.Track.objects.from_json(data)
return HttpResponse(str(track))
def post(self, request, spotify_id):
data = spt.get_song_info(spotify_id)
print(data)
return HttpResponse(data["name"])