Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 47 lines (41 sloc) 1.24 KB
#!/usr/bin/env python
Reads the line oriented output of and layers in information
where available. You'll need to add your lastfm key to
import json
import time
import config
import logging
import requests
import fileinput
def main():
logging.basicConfig(filename="lastfm.log", level=logging.INFO)
for line in fileinput.input():
a = json.loads(line)
info = lastfm(a["artist"], a["album"])
if info and info.has_key('album'):"found %s" % info["album"]["url"])
a["lastfm"] = info["album"]
logging.warn("no hit for %s/%s", a["artist"], a["album"])
print json.dumps(a)
# TODO: make this configurable
def lastfm(artist, album):
url = ''
q = {
'method': 'album.getinfo',
'api_key': config.LASTFM_KEY,
'artist': artist,
'album': album,
'format': 'json'
r = requests.get(url, params=q)
if r.status_code == 200:
return json.loads(r.content)
logging.warn("got %s when fetching info for %s/%s", (r.status_code, artist, album))
return None
if __name__ == "__main__":
Something went wrong with that request. Please try again.