class InsertSparqlTest(unittest.TestCase): def setUp(self): self.connect = VODBC.connect() self.connect.execute('SPARQL CLEAR GRAPH <%s>' % GRAPH) print 'getting myspace data' self.short_url_artist = 'kurtisrandom' self.uid_artist = '30650288' self.A = MyspaceScrape(uid=self.uid_artist) self.A.run() def test_insert_sparql(self): print 'inserting' #cursor = self.connect.cursor() self.A.insert_sparql(self.connect, GRAPH) print 'checking insert' res = self.connect.execute('''SPARQL SELECT ?same FROM <%s> WHERE { <http://dbtune.org/myspace/uid/30650288> <http://www.w3.org/2002/07/owl#sameAs> ?same } ''' % GRAPH) same = res.next()[0] assert 'http://dbtune.org/myspace/kurtisrandom' == same, 'wrong sameAs result: ' +str(same) self.connect.commit() #cursor.close() def tearDown(self): self.connect.execute('SPARQL CLEAR GRAPH <%s>' % GRAPH) self.connect.close()
def default(self, uid): if uid.endswith('.rdf'): # serve the data cherrypy.response.headers['Content-Type'] = 'application/rdf+xml; charset=UTF-8;' print USE_SPARQL sparql_match = False if USE_SPARQL: #print "USING SPARQL" # check sparql endpoint connect = VODBC.connect() cursor = connect.cursor() ss = SparqlSpace('http://dbtune.org/myspace/uid/'+str(uid.rsplit('.rdf')[0]), cursor) if ss.select(): #print "FOUND SPARQL MATCH" sparql_match = True ret = ss.make_graph() cursor.close() connect.commit() connect.close() return ret if not sparql_match: M = MyspaceScrape(uid=uid.rsplit('.rdf')[0]) M.run() if USE_SPARQL: M.insert_sparql(cursor) cursor.close() connect.commit() connect.close() return M.serialize() elif uid.endswith('.html'): # serve the html - THIS NEVER HAPPENS AND PRY NEVER WILL :p mh = Htmlify("http://dbtune.org/myspace/uid/"+uid.rsplit('.html')[0]) mh.parse_rdf() mh.get_all() return mh.html_head + mh.serialize_n3() + mh.get_available_as() +mh.html_tail else: raise cherrypy.HTTPRedirect(URL_BASE+'/uid/'+uid+'.rdf', 303)