While browsing the Phish.net API documentation I noticed that it was missing a Python wrapper. So I said to my self, this sound like a quick and fun project to test out my Python <cough> skills </cough>.
Just update the method variable to which ever method you are using and add the remaining parameters if necessary. Here is more docuemtation on the Phish.net API and where to apply for one.
While you are at it check out Adam Scheinberg and my official Phish.Net Google Chrome Extension.
FYI, This is only been tested on Python 2.7.1. I am pretty sure that it will not work in Python 3.
#Query Phish.net API via Python 2.71. import urllib, json, sys url='https://api.phish.net/' js='api.js' apikey = 'Your API Key' format = 'json' apiver = '2.0' method = 'pnet.shows.setlists.latest' #Build parameters to send via GET to api.js params = urllib.urlencode({ 'api':apiver, 'method':method, 'format':format, 'apikey':apikey }) #Attempt to open a connection and get the JSON formated data try: f = urllib.urlopen(url + js + "?%s" % params) #Do this for invalid URL except IOError: print 'Error: Unable to connect. Invalid URL. ' sys.exit(1) #Get the response code rsp = f.getcode() #If the HTTP response is 200 (OK) then proceed if rsp == 200: #Read the data data = f.read() #Decode the data as JSON decoded = json.loads(data) #Print the Decoded JSON print 'DECODED: ', decoded #Print an individual JSON Record print 'GET INDIVIDUAL RECORD: ', decoded[0]['showdate'] else: #Do this if the not an HTTP response of 200 print 'Error: ', rsp #close the connection f.close() |
I have submitted this to the Phish.net administrators and if it gets the Ok then it will be uploaded here.
Update: The code has been posted on Phish.net site.
Update 2: I forgot to give proper credit to Adam for his help on the Phish.net Chrome Extension.

