def mbid(self, urlpath):
        if urlpath.endswith('.rdf'):
            cherrypy.response.headers['Content-Type'] = 'application/rdf+xml'
            model = echonest2rdf.get_similar(urlpath.split('.rdf')[0])
            ser = RDF.RDFXMLSerializer()
            return ser.serialize_model_to_string(model, None)
        
        elif urlpath.endswith('.ttl'):
            cherrypy.response.headers['Content-Type'] = 'text/n3'
            model = echonest2rdf.get_similar(urlpath.split('.ttl')[0])
            ser = RDF.TurtleSerializer()
            return ser.serialize_model_to_string(model, None)
        
        elif urlpath.endswith('.html'):
            cherrypy.response.headers['Content-Type'] = 'text/html'
            mbid = urlpath.split('.html')[0]
            return rdf2html(echonest2rdf.get_similar(mbid),mbid)

        
        else:
            accept = cherrypy.tools.accept.callable(['text/html', 'text/plain','application/rdf+xml','text/n3']) #@UndefinedVariable
            if accept== 'text/html' or accept=='text/plain': 
                raise cherrypy.HTTPRedirect(settings.URI_BASE+'mbid/'+urlpath+'.html')
            elif accept == 'application/rdf+xml' : 
                raise cherrypy.HTTPRedirect(settings.URI_BASE+'mbid/'+urlpath+'.rdf')
            elif accept == 'text/n3' : 
                raise cherrypy.HTTPRedirect(settings.URI_BASE+'mbid/'+urlpath+'.ttl')
Exemple #2
0
 def test_get_similar(self):
     model = echonest2rdf.get_similar(JB_MBID)
     print len(model)
     model = echonest2rdf.get_similar(JOSE_MBID)
     print len(model)