def generateFeed(self): self.item = self.iframe or '<p><img src="%s" /></p>' % self.imgLink if self.itemBody and not self.itemBody.startswith('<'): self.itemBody = '<p>%s</p>' % self.itemBody self.itemBody = plagg.decode(self.itemBody) rss = self.RSS_TEMPLATE % self.__dict__ rss = plagg.encode(rss) self.feed = feedparser.parse(rss)
def processItem(self, item): """Builds the text of one Blosxom entry, saves it in self.path and sets its mtime to the timestamp, if present.""" entry = Entry() entry.setFromItem(self.feed, self.channel, item) if not entry.write(self.fdir, self.fext): return if entry._title: self.new.append(entry) # logging if self.logging: name = '' if self.logged else plagg.encode(self.name) + '\n' self.logged = True plagg.pprint(name + ' ' + entry.logSummary())
def render(self): """Renders itself, including any metas, if any.""" s = [self.title] if self.metas: # this needs the Blosxom "meta" plugin! for m in self.metas.items(): s.append('meta-%s: %s' % m) s.append('') s.append(self.body) if self.item and self.item.get('media_content'): s.append('<p class="blosxomMedia">') for c in self.item['media_content']: url = c['url'] name = urlsplit(url).path.split('/')[-1] s.append('<a href="%s">%s</a>' % (url, name)) s.append('</p>') s.append(self.footer) return plagg.encode(u'\n'.join(map(plagg.decode, s)))
def tidy(self, body): body = plagg.encode(body) if plagg.VERBOSE > 3: print 'before tidy:', body tidy = ['/usr/bin/tidy', '-asxhtml', '-utf8', '-f', '/dev/null'] try: t = subprocess.Popen( tidy, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) r = t.communicate(body)[0] except OSError: if not Entry.TidyWarningDone: sys.stderr.write("Cannot execute %s\n" % ' '.join(tidy)) Entry.TidyWarningDone = True else: if 0 <= t.returncode <= 1: # warnings are ok # Keep the part between <body> and </body> m = _body.search(r) body = (m.group(1) if m else r).strip() elif plagg.VERBOSE > 3: print "tidy errors; body left as-is" % t.returncode if plagg.VERBOSE > 3: print 'after tidy:', body return plagg.decode(body)
def logSummary(self): return self.timestamp(': ') + \ plagg.encode(_markup.sub('', self._title) or self.fname)