David Reynolds

Welcome to boredom

Last.fm

| Comments

Having a few spare minutes, I’ve added a template tag to my site that shows the last 10 songs I’ve listened to on last.fm.

1
2
3
4
5
6
7
8
9
10
11
@register.inclusion_tag('blog/lastfm_tracks.html')
def latest_tracks():
    url = 'http://ws.audioscrobbler.com/1.0/user/DReynolds/recenttracks.txt'
    response = urllib2.urlopen(url)
    songs = []
    for line in response.read().split('\n'):
        if not re.match(r"^$", line):
            songdetail = re.split(",", line)[1]
            artist, song = re.split(" \xe2\x80\x93 ",  songdetail)
            songs.append({'artist' : artist, 'song' : song})
    return {'songs' : songs}

Comments