Python Wrapper For The Phish.net API

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.

Official Phish.net Google Chrome Extension

Here is the release announcement for the Official Phish.net Google Chrome extension that myself and Adam Scheinberg have been working on.

We’re proud to unveil the official Phish.net Google Chrome extension. Written by user Terry Moore and blessed by the Phish.net tech team, this extension utilizes Phish.net API goodness to deliver setlists and forum posts right into your browser.

via Phish.net

Phish Announces Fall Tour

phish_logo

11.18.09 Cobo Arena, Detroit, MI
11.20.09 U.S. Bank Arena, Cincinnati, OH
11.21.09 U.S. Bank Arena, Cincinnati, OH
11.22.09 War Memorial at Oncenter , Syracuse, NY
11.24.09 Wachovia Center, Philadelphia, PA
11.25.09 Wachovia Center, Philadelphia, PA
11.27.09 Times Union Center, Albany, NY
11.28.09 Times Union Center, Albany, NY
11.29.09 Cumberland County Civic Center, Portland, ME
12.02.09 Madison Square Garden , New York, NY
12.03.09 Madison Square Garden, New York, NY
12.04.09 Madison Square Garden, New York, NY
12.05.09 John Paul Jones Arena, Charlottesville, VA

I would love to do the Detroit to Cincinnati run.  Now, if I only had the funds.  Plus this conflicts with the OSU vs Michigan game on the 21st.