Exemple #1
0
def set_song():
    if request.form['spotify_uri'] and request.form['song_date']:
        song_details = get_song_details(request.form['spotify_uri'])
        new_song = DailySong(created_on=dateutil.parser.parse(request.form['song_date']).date(),
                             **song_details)
        new_song.insert()
        safe_commit()

    flash('Song set successfully!', 'success')
    return redirect(url_for('get_daily_songs'))
Exemple #2
0
def get_song_details(track_uri):
    '''
    '''
    spotify_lookup_base = 'http://ws.spotify.com/lookup/1/?uri='
    song_details = {}
    track_info = urllib2.urlopen(''.join([spotify_lookup_base, track_uri])).read()
    detail_soup = BeautifulSoup(track_info)

    song_details['track_uri'] = track_uri
    song_details['track_name'] = detail_soup.find('track').find('name').get_text()

    artist = detail_soup.find('artist')
    song_details['artist_uri'] = artist.get('href')
    song_details['artist_name'] = artist.find('name').get_text()

    album = detail_soup.find('album')
    song_details['album_uri'] = album.get('href')
    song_details['album_name'] = album.find('name').get_text()

    album_seen_before = DailySong.filter_by(album_uri=song_details['album_uri']).first()

    if not album_seen_before:
        retrieve_album_art(song_details['album_uri'])

    return song_details
Exemple #3
0
def get_song_of_the_day(today=None):
    if not today:
        today = datetime.now().date()

    song_of_the_day = DailySong.filter(func.date(DailySong.created_on) == today).first()
    return song_of_the_day
Exemple #4
0
def get_daily_songs():
    songs = DailySong.order_by(DailySong.created_on.desc()).all()
    song_of_the_day = get_song_of_the_day()
    return render_template('daily_songs.html', songs=songs,
                           song_of_the_day=song_of_the_day)
Exemple #5
0
def get_song_of_the_day():
    today = datetime.now().date()
    song_of_the_day = DailySong.filter(created_on=today).first()
    return song_of_the_day