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 setFromItem(self, feed, channel, item): """Initializes self from a feed channel and item. The item's title and link are both optional. The following logic determines what goes where: - if there's a title and a link, the title becomes the link. - if there's no title but a link, the link goes into the footer. The footer consists of the date, the item link (if present and no title), an optional comments link, and the channel link.""" self.channel = channel self.item = item self.setMeta(source=feed.attrs['nick']) # body bodytype = feed.attrs.get('body', '') if bodytype == 'none': body = '' else: body = ( bodytype != 'summary' and item.get('content', [{}])[0].get('value') or item.get('summary', '') ).strip() body = feed.replaceText('body', body) if body and not body.startswith('<'): body = '<p>' + body + '</p>' try: adj = int(feed.attrs['h-adjust']) except (KeyError, ValueError): pass else: body = _h14.sub( lambda m: '%s%d>' % (m.group(1), int(m.group(2)) + adj), body ) self.body = body # title title = _unescape(item.get('title', '').replace('\n', ' ')).strip() title = feed.replaceText('title', title) # remove the title if it matches the start of the body (for tumblr quotes) if len(title) > 20 and title[0] == title[-1] == '"': if title.count('"') == 2: title = title[1:-1].rstrip('.') if title in self.body: title = '' elif title.endswith(u'...') and title[:-3] in self.body: title = '' self._title = title # link self._link = item.get('link') # if the body starts with a link, use it and delete it from the body m = _link.match(self.body) if m: link = m.group(1) self.body = self.body[m.end():] else: link = self._link if self._title and link: self.title = _linktag(link, self._title) else: self.title = self._title if feed.attrs.get('tidy', 'yes') == 'yes': self.body = self.tidy(self.body) # tags if 'tags' in item: self.setMeta(tags=' '.join(t.term.replace(' ', '+') for t in item.tags)) # footer if plagg.FOOTER: footer = '\n<p class="blosxomEntryFoot">' + ( item.get('date') or item.get('modified', '') ) if self._link and (len(self.body) > 2500 or self._link != link): footer += '\n[%s]' % _linktag(self._link, 'Link') if 'comments' in item: footer += '\n[%s]' % _linktag(item['comments'], 'Comments') footer += '\n[%s]\n</p>\n' % _linktag( channel['link'], channel['title'], title=channel.get('tagline') ) self.footer = footer # modification time if feed.attrs.get('ignoredate', 'no') != 'yes': self.mdate = item.get('date_parsed') or item.get('modified_parsed') or \ item.get('updated_parsed') if self.mdate: # convert date/time 9-tuple in UTC to timestamp self.tm = time.mktime(self.mdate[:8] + (-1, )) - tz self.mdate = time.localtime(self.tm) # convert timestamp to local 9-tuple if plagg.VERBOSE > 1: plagg.pprint(('new item', self.__dict__))