Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use YQL to return track data upon receiving a tweet with #Nowplaying #openhackindia
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()
song = tweet.split('#nowplaying')[0].trim()
YQLQuery = urllib2.quote('select ','')
YQLQuery = YQLQuery + '*'
YQLQuery = YQLQuery + urllib2.quote(' from where keyword=','')
YQLQuery = YQLQuery + '"'+ urllib2.quote(song,'') +'"'
url = ''+YQLQuery + '&diagnostics=true&env='
url = url + urllib2.quote('store://','')
request = urllib2.Request(url)
request.add_header('User-Agent','LWLater 1.0')
opener = urllib2.build_opener()
YQLResp =
soupXml = BeautifulSoup(YQLResp)
track = soupXml.findAll('track')[0]
self.response.headers['Content-Type'] = 'text/html'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment