def AddFlipnote(self, content, Channel=""): #content = ppm binary data tmb = TMB().Read(content) if not tmb: return False #CreatorID = tmb.Username if fnregex.match(tmb.EditorAuthorID): CreatorID = tmb.EditorAuthorID if fnregex.match(tmb.CurrentFilename[:-4]): filename = tmb.CurrentFilename[:-4] del tmb if self.FlipnoteExists(CreatorID, filename): #already exists return False #add to database: leafcur.execute( "INSERT INTO `flipnotes` (creatorid, flipnote) VALUES ('%s', '%s')" % (CreatorID, filename)) leafconn.commit() if not self.GetCreator(CreatorID, True): self.Creator[CreatorID] = [[filename, 0, 0, Channel, 0]] else: self.Creator[CreatorID].append([filename, 0, 0, Channel, 0]) #write flipnote to file: if not os.path.isdir("database/Creators/" + CreatorID): os.mkdir("database/Creators/" + CreatorID) f = open(self.FlipnotePath(CreatorID, filename), "wb") f.write(content) f.close() return CreatorID, filename
def AddFlipnote(self, content, Channel=""): #content = ppm binary data tmb = TMB().Read(content) if not tmb: return False #CreatorID = tmb.Username CreatorID = tmb.EditorAuthorID filename = tmb.CurrentFilename[:-4] del tmb if self.FlipnoteExists(CreatorID, filename): #already exists return False #add to database: self.new = True self.Newest.insert(0, (CreatorID, filename)) if not self.GetCreator(CreatorID, True): self.Creator[CreatorID] = [[ filename, 0, 0, 0, 0, 0, 0, Channel, 0 ]] else: self.Creator[CreatorID].append( [filename, 0, 0, 0, 0, 0, 0, Channel, 0]) #write flipnote to file: if not os.path.isdir("database/Creators/" + CreatorID): os.mkdir("database/Creators/" + CreatorID) f = open(self.FlipnotePath(CreatorID, filename), "wb") f.write(content) f.close() return CreatorID, filename
def GenerateDetailsPage(self, CreatorID, filename):#filename without ext flipnote = Database.GetFlipnote(CreatorID, filename)#flipnote = [filename, views, stars, green stars, red stars, blue stars, purple stars, Channel], all probably strings if not flipnote: return "This flipnote doesn't exist!" tmb = TMB().Read(Database.GetFlipnoteTMB(CreatorID, filename)) if not tmb: return "This flipnote is corrupt!" #Is it a spinoff? Spinnoff = "" if tmb.OriginalAuthorID <> tmb.EditorAuthorID or tmb.OriginalFilename <> tmb.CurrentFilename: if Database.FlipnoteExists(tmb.OriginalAuthorID, tmb.OriginalFilename[:-4]): Spinnoff = SpinoffTemplate1.replace("%%CreatorID%%", tmb.OriginalAuthorID).replace("%%Filename%%", tmb.OriginalFilename[:-4]) elif tmb.OriginalAuthorID <> tmb.EditorAuthorID: Spinnoff = SpinoffTemplate2 #make each entry: Entries = [] #Creator username: name = "Creator" #content = "<a href=\"http://flipnote.hatena.com/ds/ds/v2-xx/%s/profile.htm?t=260&pm=80\">%s</a>" % (CreatorID, tmb.EditorAuthorName) content = '<a href="http://flipnote.hatena.com/ds/v2-xx/%s/profile.htm?t=260&pm=80\">%s</a>' % (CreatorID, tmb.Username) Entries.append(PageEntryTemplate.replace("%%Name%%", name).replace("%%Content%%", content)) #Stars: name = "Stars" content = u'<a href="http://flipnote.hatena.com/ds/v2-xx/movie/%s/%s.htm?mode=stardetail"><span class="star0c">\u2605</span> <span class="star0">%s</span></a>' % (CreatorID, filename, flipnote[2])#yellow stars #todo: add other stars Entries.append(PageEntryTemplate.replace("%%Name%%", name).replace("%%Content%%", content)) #Views: name = "Views" content = str(flipnote[1]) Entries.append(PageEntryTemplate.replace("%%Name%%", name).replace("%%Content%%", content)) #Channel: if flipnote[7]:#todo: make channels work at all name = "Channel" content = 'a href="http://flipnote.hatena.com/ds/v2-xx/ch/%s.uls">%s</a>' % (flipnote[7], flipnote[7]) Entries.append(PageEntryTemplate.replace("%%Name%%", name).replace("%%Content%%", content)) #Comments: Comments = "0" #doto: add original author info too #add the entries to page: return DetailsPageTemplate.replace("%%CreatorID%%", CreatorID).replace("%%Filename%%", filename).replace("%%CommentCount%%", Comments).replace("%%Spinoff%%", Spinnoff).replace("%%PageEntries%%", PageEntrySeparator.join(Entries))