Exemplo n.º 1
0
 def add_root_elements(self, handler):
     handler.addQuickElement(u"title", self.feed['title'])
     handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']})
     if self.feed['link'] is not None:
         handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']})
     handler.addQuickElement(u"id", self.feed['id'])
     handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('utf-8'))
     if self.feed['author_name'] is not None:
         handler.startElement(u"author", {})
         handler.addQuickElement(u"name", self.feed['author_name'])
         if self.feed['author_email'] is not None:
             handler.addQuickElement(u"email", self.feed['author_email'])
         if self.feed['author_link'] is not None:
             handler.addQuickElement(u"uri", self.feed['author_link'])
         handler.endElement(u"author")
     if self.feed['subtitle'] is not None:
         handler.addQuickElement(u"subtitle", self.feed['subtitle'])
     for cat in self.feed['categories']:
         handler.addQuickElement(u"category", "", {u"term": cat})
     if self.feed['feed_copyright'] is not None:
         handler.addQuickElement(u"rights", self.feed['feed_copyright'])
     if self.feed['logo'] is not None:
         handler.addQuickElement(u"logo", self.feed['logo'])
     if self.feed['icon'] is not None:
         handler.addQuickElement(u"icon", self.feed['icon'])
     if self.feed['image'] is not None:
         handler.addQuickElement(u"p2pnext:image", "", {u"src": self.feed['image']})
Exemplo n.º 2
0
    def add_item_elements(self, handler, item):
        handler.addQuickElement(u"title", item['title'])
        if item['link'] is not None:
            if item['link_type'] is not None:
                handler.addQuickElement(u"link", u"", {u"href": item['link'], u"rel": u"alternate", u"type": item['link_type']})
            else:
                handler.addQuickElement(u"link", u"", {u"href": item['link'], u"rel": u"alternate"})
        if item['pubdate'] is not None:
            handler.addQuickElement(u"updated", rfc3339_date(item['pubdate']).decode('utf-8'))
        else:
            handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('utf-8'))

        # Author information.
        if item['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", item['author_name'])
            if item['author_email'] is not None:
                handler.addQuickElement(u"email", item['author_email'])
            if item['author_link'] is not None:
                handler.addQuickElement(u"uri", item['author_link'])
            handler.endElement(u"author")

        # Unique ID.
        if item['unique_id'] is not None:
            unique_id = item['unique_id']
        else:
            self._generate_item_id(item)
        handler.addQuickElement(u"id", item['unique_id'])

        # Summary.
        if item['description'] is not None:
            if item['description_type'] is not None:
                handler.addQuickElement(u"summary", item['description'], {u"type": item['description_type']})
            else:
                handler.addQuickElement(u"summary", item['description'])

        # Enclosure.
        if item['enclosure'] is not None:
            handler.addQuickElement(u"link", '',
                {u"rel": u"enclosure",
                 u"href": item['enclosure'].url,
                 u"length": item['enclosure'].length,
                 u"type": item['enclosure'].mime_type})

        # Categories.
        for cat in item['categories']:
            if isinstance(cat, str) or isinstance(cat, unicode):
                handler.addQuickElement(u"category", u"", {u"term": cat})
            elif isinstance(cat, tuple):
                if len(cat) <= 3:
                    w = [u"term", u"schema", u"label"]
                    handler.addQuickElement(u"category", u"", dict((w[cat.index(c)],c) for c in cat if c))

        # Rights.
        if item['item_copyright'] is not None:
            handler.addQuickElement(u"rights", item['item_copyright'])

        # Content. Do we need to do anything else?
        if item['content'] is not None:
            handler.addQuickElement(u"content", item['content'])

        # Image
        if item['image'] is not None:
            handler.addQuickElement(u"p2pnext:image", "", {u"src": item['image']})