Example #1
0
def test_get_perf_by_id():
    db.session.add(Song(name="Slippery When Wet"))
    db.session.add(Artist(name="Commodores"))
    db.session.add(Concert(name="Glastonbury"))
    db.session.add(Performance(rating=randint(5, 10), song_id=1, concert_id=1))
    res = client.get("/api/performances/1")
    assert res.json["perf_id"] == 1
Example #2
0
def test_search():
    db.session.add(Song(name="Slippery When Wet"))
    db.session.add(Artist(name="Commodores"))
    db.session.add(Concert(name="Glastonbury"))
    db.session.add(Performance(rating=randint(5, 10), song_id=1, concert_id=1))
    db.session.commit()
    res = search(query="Slippery When Wet", page=1, concert=1)
    assert res.items[0].song.name == "Slippery When Wet"
Example #3
0
 def write_to_db(self) -> None:
     for song_name, artist_name, song_bytes in self.get_song_list_for_db():
         print(
             f"Trying adding song: {song_name} by artist: {artist_name} to database"
         )
         try:
             song = Song(name=song_name,
                         artist=artist_name,
                         mp3_file=song_bytes)
             db.session.add(song)
             db.session.commit()
             print('Success: wrote song to db')
         except Exception as e:
             print('Fail: error occurred while trying to write song to db.')
             raise Exception(e)
Example #4
0
def addSong():
    print("Add song called.")

    if not room:
        return 'False'

    # Extract song name from text message
    song_name = request.form.get('Body')
    print("Received song {}, extracting information from Spotify API".format(
        song_name))

    # Search for the song ID on Spotify
    headers = {'Authorization': 'Bearer {}'.format(access_token)}
    params = {'q': song_name, 'type': 'track,artist', 'limit': '1'}
    song_response = requests.get('https://api.spotify.com/v1/search',
                                 headers=headers,
                                 params=params)

    print(json.loads(song_response.text))
    if song_response.status_code != 200:
        return 'False'

    song_response_json = json.loads(song_response.text)
    track = song_response_json['tracks']['items'][0]
    song_id = track['id']

    # Get features vector for song from Spotify
    features_response = requests.get(
        'https://api.spotify.com/v1/audio-features/{}'.format(song_id),
        headers=headers)
    if features_response.status_code != 200:
        return 'False'

    features_response_json = json.loads(features_response.text)
    # construct a features list representing relevant features
    features = [
        float(features_response_json[x]) for x in features_response_json
        if x in relevant_features
    ]
    # print(features_response_json)

    song = Song.Song(song_id, song_name, features)
    room.add_song(song)
    print(room.queue)
    return 'True'
Example #5
0
        "name": "Come Home"
    },
    {
        "album_id": 5,
        "name": "Don't Look Now"
    },
    {
        "album_id": 5,
        "name": "Rocketeer"
    },
    {
        "album_id": 6,
        "name": "Life in Technicolor"
    },
    {
        "album_id": 6,
        "name": "Cemeteries of London"
    },
    {
        "album_id": 6,
        "name": "Viva la Vida"
    },
)

for s in songs:
    song = Song(**s)
    db.session.add(song)

db.session.commit()
db.session.close()
Example #6
0
    print "Creating tables..."
    db.create_all()

    with open(fixture_path) as fixture_file:
        fixtures = json.load(fixture_file)

    for artist in fixtures:
        print 'Creating artist: {}'.format(artist['name'])
        _artist = Artist(name=artist['name'], bio=artist['bio'])

        db.session.add(_artist)

        for album in artist['albums']:
            print ' Creating album: {}'.format(album['name'])
            _album = Album(name=album['name'],
                           artwork_url=album['artwork_url'],
                           artist=_artist)

            db.session.add(_album)

            for song in album['songs']:
                print '     Creating song: {}'.format(song['name'])
                _song = Song(name=song['name'],
                             album=_album,
                             url=song['url'],
                             duration=song['duration'])

                db.session.add(_song)

        db.session.commit()
Example #7
0
print("\n 🌱 seeding db... \n")

db.drop_all()
db.create_all()

artists = [Artist(name="Massive Attack"), Artist(name="Nas")]
for a in artists:
    db.session.add(a)
db.session.commit()

massive_attack = Artist.query.get(1)
nas = Artist.query.get(2)

songs = [
    Song(name="One Love", artist=massive_attack),
    Song(name="One Love", artist=nas),
    Song(name="Protection", artist=massive_attack),
    Song(name="Black Bond", artist=nas),
    Song(name="The World is Yours", artist=nas),
    Song(name="Bye Baby", artist=nas),
]
for s in songs:
    db.session.add(s)
db.session.commit()

for _ in range(0, 500):
    performance = Performance(
        rating=randint(5, 10), song_id=randint(1, 6), concert_id=randint(1, 3)
    )
    db.session.add(performance)