Esempio n. 1
0
def seed_gen():
    en = pyen.Pyen(APIKEY)
    all_songs = Song.objects.all()
    for song in all_songs:
        artist = Artist.objects.filter(name=song.artist)
        if len(artist) == 0:
            try:
                print(song.artist)
                new_artist = Artist(name=song.artist)
                new_artist.save()
                response = en.get('artist/profile',
                                  name=song.artist,
                                  bucket=['genre'])
                genres = response['artist']['genres']
                for genre in genres:
                    existing = Genre.objects.filter(name=genre['name'])
                    if len(existing) == 0:
                        genre_object = Genre(name=genre['name'])
                        genre_object.save()
                        print(genre)
                    else:
                        genre_object = existing[0]
                    new_artist.genres.add(genre_object)
                new_artist.save()
            except:
                continue
Esempio n. 2
0
def seed_genre(artist_name):
    en = pyen.Pyen(APIKEY)
    new_artist = Artist(name=artist_name)
    new_artist.save()
    try:
        response = en.get('artist/profile', name=artist_name, bucket=['genre'])
        genres = response['artist']['genres']
        for genre in genres:
            existing = Genre.objects.filter(name=genre['name'])
            if len(existing) == 0:
                genre_object = Genre(name=genre['name'])
                genre_object.save()
                print(genre)
            else:
                genre_object = existing[0]
                new_artist.genres.add(genre_object)
            new_artist.save()
    except:
        pass
    return new_artist
Esempio n. 3
0
def seed_genre(artist_name):
    en = pyen.Pyen(APIKEY)
    new_artist = Artist(name=artist_name)
    new_artist.save()
    try:
        response = en.get("artist/profile", name=artist_name, bucket=["genre"])
        genres = response["artist"]["genres"]
        for genre in genres:
            existing = Genre.objects.filter(name=genre["name"])
            if len(existing) == 0:
                genre_object = Genre(name=genre["name"])
                genre_object.save()
                print(genre)
            else:
                genre_object = existing[0]
                new_artist.genres.add(genre_object)
            new_artist.save()
    except:
        pass
    return new_artist
Esempio n. 4
0
def seed_gen():
    en = pyen.Pyen(APIKEY)
    all_songs = Song.objects.all()
    for song in all_songs:
        artist = Artist.objects.filter(name=song.artist)
        if len(artist) == 0:
            try:
                print(song.artist)
                new_artist = Artist(name=song.artist)
                new_artist.save()
                response = en.get('artist/profile', name=song.artist, bucket=['genre'])
                genres = response['artist']['genres']
                for genre in genres:
                    existing = Genre.objects.filter(name=genre['name'])
                    if len(existing) == 0:
                        genre_object = Genre(name=genre['name'])
                        genre_object.save()
                        print(genre)
                    else:
                        genre_object = existing[0]
                    new_artist.genres.add(genre_object)
                new_artist.save()
            except:
                continue