PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/pyechonest/examples/tempo.py

http://echo-nest-remix.googlecode.com/
Python | 23 lines | 18 code | 5 blank | 0 comment | 4 complexity | cc73c26fa50b6bf14d8f514bfcd2dcdd MD5 | raw file
 1import sys
 2from pyechonest import song
 3
 4def get_tempo(artist, title):
 5    "gets the tempo for a song"
 6    results = song.search(artist=artist, title=title, results=1, buckets=['audio_summary'])
 7    if len(results) > 0:
 8        return results[0].audio_summary['tempo']
 9    else:
10        return None
11
12
13if __name__ == '__main__':
14    if len(sys.argv) <> 3:
15        print "Usage: python tempo.py 'artist name' 'song title'"
16    else:
17        tempo = get_tempo(sys.argv[1], sys.argv[2])
18        if tempo:
19            print 'Tempo for', sys.argv[1], sys.argv[2], 'is', tempo
20        else:
21            print "Can't find Tempo for artist:", sys.argv[1], 'song:', sys.argv[2]
22        
23