def is_artist(self): '''do artist check, assign a self.subject (Person or MusicArtist) and return True or False''' genrePresent = scrapePage(self.html, [uris.genreTag[0]], uris.genreTag[1]) if genrePresent: self.subject = mopy.mo.MusicArtist(uris.dbtune+'uid/'+str(self.uid)) # add foaf:primaryTopic ppd = mopy.foaf.PersonalProfileDocument("") ppd.primaryTopic.set(self.subject) self.mi.add(ppd) # assuming the 'name' tag must be present, if not it's a bad url self.name = scrapePage(self.html, [uris.nameTag[0]], uris.nameTag[1]) if self.name: self.subject.name.set(self.name) else: raise MyspaceException, "seems to be an invalid - could not find foaf:name" return True else: self.subject = mopy.foaf.Person(uris.dbtune+'uid/'+str(self.uid)) # add foaf:primaryTopic ppd = mopy.foaf.PersonalProfileDocument("") ppd.primaryTopic.set(self.subject) self.mi.add(ppd) self.name = self.soup.title.string.strip('\r').strip('\t').strip('\n').split(uris.non_artist_name_split)[0].strip() #print self.name if self.name: self.subject.name.set(self.name) else: raise MyspaceException, "seems to be an invalid - could not find foaf:name" return False
def get_image(self): imageURL = scrapePage(self.html, [uris.picTag[0]+str(self.uid)+'''"><img src="'''], uris.picTag[1]) if imageURL != None: img = mopy.foaf.Image(imageURL) self.subject.depiction.add(img) self.mi.add(img) return imageURL
def get_nice_url(self): niceURL = scrapePage(self.html, [uris.niceURLTag[0]], uris.niceURLTag[1]) if niceURL: niceURL = niceURL.rsplit(uris.www_myspace)[1] thing = mopy.owl.Thing(uris.dbtune+niceURL) self.subject.sameAs.set(thing) self.mi.add(thing) return niceURL
def get_stats(self): # country locality mess = scrapePage(self.html, [uris.cityTag[0]], uris.cityTag[2]) if mess != None: locality = mess.split(uris.cityTag[1])[0] country = mess.split(uris.cityTag[1])[1] self.subject.country.set(str(unicode(country).encode('utf-8'))) self.subject.locality.set(str(unicode(locality).encode('utf-8'))) # geoname foaf:based_near for country - outside of MoPy self.non_mopy_graph.append((URIRef(self.subject.URI), FOAF['based_near'], URIRef(COUNTRIES[country]))) # profile views profile_views = scrapePage(self.html, [uris.profileViews[0]], uris.profileViews[1]) if profile_views != None: self.subject.profileViews.set(int(profile_views)) # total friend count try: totfri = self.soup.find(property="myspace:friendCount").string except AttributeError, err: totfri = '0'
def get_genres(self): '''get the genres for an artist''' localGenres = scrapePage(self.html, [uris.genreTag[0]], uris.genreTag[1]) if localGenres == None: return None genreNums = re.findall(''':"([0-9]+)"''', localGenres) # should return only 2 or 3 char string between genres = [] for gnum in genreNums: try: genre = mopy.mo.Genre(uris.myspaceOntology+quote(uris.genreDict[int(gnum)])) except KeyError: pass else: genre.name.set(uris.genreDict[int(gnum)]) self.mi.add(genre) self.subject.genreTag.add(genre) genres.append(genre) return genres
def get_uid(self): ''' get the uid from the html ''' self.uid = scrapePage(self.html, [uris.userIDTag[0]], uris.userIDTag[1])