Here’s a little python script that displays a user’s Klout score. It can be run from the command line like this:
[smbrown@smbrown ~]$ klout-score.py smbrown
Or you can add it as an extension to Alfred App if you have the Powerpack.
Invoke Alfred App, type the extension shortcut, twitter username and see the user’s Klout score in less time then it takes to open and load http://klout.com/username.
Marcel Pinheiro Caraciolo has built a nice Python interface to the Klout API, definitely look into using that for anything more complicated then this simple use case.
If the script below is on your path and you can run it from the command like above, then this Alfred App Powerpack extension should do the trick
-- Alfred App Extension:
#Desc: Retrieve user's Klout score
#Use: ks <query>
#Ex: ks smbrown
URL=$(klout-score.py "{query}")
echo -n $URL
-- Python script follows:
#! /usr/bin/python
import httplib
import simplejson as json
import sys
if len(sys.argv) < 2:
sys.exit(2)
user = sys.argv[1]
klout_key = "I-am-an-idiot-for-posting-the-version-of-this-snippet-with-my-real-key"
api_url = "/1/klout.json?users=%s&key=%s" % (user, klout_key)
api_domain = "api.klout.com"
conn = httplib.HTTPConnection(api_domain)
conn.request('GET', api_url)
resp = conn.getresponse()
data = resp.read()
data = json.loads(data)
print data['users'][0]['score']