Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2011 01:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
LastFM session key generator
#!/usr/bin/env python
import sys, md5
import pycurl, simplejson, webbrowser
class CurlReader:
def __init__(self):
self.contents = ''
def body_callback(self, buf):
self.contents = self.contents + buf
def curl(url):
t = CurlReader()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, t.body_callback)
return t.contents
api_key = sys.argv[1]
api_sec = sys.argv[2]
print "API Key",api_key
print "Secret ",api_sec
print "Requesting an auth token."
response = simplejson.loads(curl("" + api_key))
token = response["token"]
print "Token: ",token"" + api_key + "&token=" + token)
raw_input("(Press enter when you're done)")
print "Requesting a session key, this is your `sk` value."
sig ="api_key" + api_key + "methodauth.getSession" + "token" + token + api_sec).hexdigest()
print "Signat:",sig
response = simplejson.loads(curl("" + api_key + "&token=" + token + "&api_sig=" + sig))
print "User: ",response["session"]["name"]
print "Key: ",response["session"]["key"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment