当前位置: 首页>>代码示例>>Python>>正文


Python SubElement.attrib["domain"]方法代码示例

本文整理汇总了Python中elementtree.ElementTree.SubElement.attrib["domain"]方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.attrib["domain"]方法的具体用法?Python SubElement.attrib["domain"]怎么用?Python SubElement.attrib["domain"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elementtree.ElementTree.SubElement的用法示例。


在下文中一共展示了SubElement.attrib["domain"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetFeedElement

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import attrib["domain"] [as 别名]
def GetFeedElement(feed):
    """Create an atom:feed element for the provided feed.

    The provided feed must be in the format described at http://feedparser.org.
    """

    rss = Element("rss")
    rss.attrib["version"] = "2.0"

    root = SubElement(rss, "channel")

    TextElement(root, "title", feed.feed.get("title_detail"))
    if feed.feed.has_key("links"):
        for link in feed.feed.links:
            if link.rel != "self": continue
            SubElementIf(root, "link", link.href)
    
    TextElement(root, "description", feed.feed.get("subtitle_detail"))
    TextElement(root, "copyright", feed.feed.get("rights_detail"))
    SubElement(root, "generator").text = "feedarchive"
    
    if feed.feed.has_key("image"):
        im = feed.feed.image
        ie = SubElement(root, "image")
        SubElementIf(ie, "url", im.get("href"))
        SubElementIf(ie, "title", im.get("title"))
        SubElementIf(ie, "link", im.get("link"))

    if feed.feed.has_key("tags"):
        for tag in feed.feed.tags:
            te = SubElement(root, "category")
            if (tag.has_key("scheme")): te.attrib["domain"] = tag.scheme
            te.text = tag.term

    for entry in feed.entries:
        ee = SubElement(root, "item")
        TextElement(ee, "title", entry.get("title_detail"))
        SubElementIf(ee, "link", entry.get("link"))
        TextElement(ee, "description", entry.get("summary_detail"))
        SubElementIf(ee, "guid", entry.get("id"))
        DateTimeElement(ee, "pubDate", entry, "published")
        PersonElement(ee, "author", entry.get("author_detail"))

        if entry.has_key("links"):
            for link in entry.links:
                if link.rel != "enclosure": continue
                ence = SubElement(ee, "enclosure")
                AttribIf(ence, "url", link.get("url"))
                AttribIf(ence, "length", link.get("length"))
                AttribIf(ence, "type", link.get("type"))
                
    return rss
开发者ID:DeCarabas,项目名称:feedarchive,代码行数:54,代码来源:rsswriter.py


注:本文中的elementtree.ElementTree.SubElement.attrib["domain"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。