Created
July 31, 2011 02:48
-
-
Save srikanthlogic/1116320 to your computer and use it in GitHub Desktop.
Use YQL to return track data upon receiving a tweet with #Nowplaying #openhackindia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cgi | |
import datetime | |
import wsgiref.handlers | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup | |
from google.appengine.ext import webapp | |
class MainPage(webapp.RequestHandler): | |
def post(self): | |
tweet = self.request.get('tweet') | |
if (tweet.split('#nowplaying')[0] == ''): | |
song = tweet.split('#nowplaying')[1].trim() | |
else: | |
song = tweet.split('#nowplaying')[0].trim() | |
YQLQuery = urllib2.quote('select ','') | |
YQLQuery = YQLQuery + '*' | |
YQLQuery = YQLQuery + urllib2.quote(' from music.track.search where keyword=','') | |
YQLQuery = YQLQuery + '"'+ urllib2.quote(song,'') +'"' | |
url = 'http://query.yahooapis.com/v1/public/yql?q='+YQLQuery + '&diagnostics=true&env=' | |
url = url + urllib2.quote('store://datatables.org/alltableswithkeys','') | |
request = urllib2.Request(url) | |
request.add_header('User-Agent','LWLater 1.0') | |
opener = urllib2.build_opener() | |
YQLResp = opener.open(request).read() | |
soupXml = BeautifulSoup(YQLResp) | |
track = soupXml.findAll('track')[0] | |
self.response.headers['Content-Type'] = 'text/html' | |
self.response.out.write(track) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment