Making pylast.py play with Google App Engine
I have been playing with Google App Engine and last.fm’s api for a while now. I made the standard mistake of not checking if anyone else had written a library in Python to do the hard work for me. So, after a little googling I found pyLast which is a great piece of work by Amr Hassan. After a little playing I found that it didn’t play well with App Engine. This was down to the it not using urlfetch, which is no big surprise as thats a feature unique to App Engine. I also noticed it was missing the ability to fetch the date and start time of an event.
So below is a patch to App Engine up the code and fetch the date/time of an event. There is a slight oddity I have yet to figure out, the time gets appended to the date. I cant see any sane reason why currently.
Be warned this breaks the module for standard Python use unless you are have google.appengine.api kicking around in your module path.
If you wish to try out my App Engine app its over at Cassandra. Just enter the name of the artist to find out where they are playing displayed on Google Maps. Its very much an ongoing project…
diff pylast.py pylast.py.orig
37d36
< from google.appengine.api import urlfetch
286,287c285,292
< request = 'http://' + API_SERVER + API_SUBDIR + '?method=' + '&'.join(data)
< response = urlfetch.fetch(request)
---
> conn = httplib.HTTPConnection(API_SERVER)
> headers = {
> "Content-type": "application/x-www-form-urlencoded",
> 'Accept-Charset': 'utf-8',
> 'User-Agent': __name__ + '/' + __version__
> }
> conn.request('POST', API_SUBDIR, '&'.join(data), headers)
> response = conn.getresponse()
292c297
< doc = minidom.parseString(response.content)
---
> doc = minidom.parse(response)
404a410
>
1391,1392d1396
< data['date'] = self._extract(doc, 'startDate')
< data['time'] = self._extract(doc, 'startTime')
1482,1497c1486
<
< def getStartDate(self):
< """Returns the start date of the event """
<
< return self._getCachedInfo('date')
<
< def getStartTime(self):
< """Returns the start time of the event """
<
< return self._getCachedInfo('time')
<
< def getReviewCount(self):
< """Returns the number of available reviews for this event. """
<
< return self._getCachedInfo('reviews')
<
---
>

