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


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

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


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

示例1: CreateSourceElement

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import attrib["term"] [as 别名]
def CreateSourceElement(ee, feed):
    """Create an atom:source element in the provided entry element,
    based on the provided feed metadata.
    """
    if not feed: return
    
    root = SubElement(ee, "source")
    TextElement(root, "title", feed.get("title_detail"))
    if feed.has_key("links"):
        for link in feed.links:
            LinkElement(root, "link", link)
            
    TextElement(root, "subtitle", feed.get("subtitle_detail"))
    TextElement(root, "rights", feed.get("rights_detail"))
    SubElement(root, "generator").text = "feedarchive"
    SubElement(root, "updated").text = rfc3339(time.time())
    SubElementIf(root, "id", feed.get("id"))
    
    if feed.has_key("image"):
        SubElement(root, "icon").text = feed.image.href

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

    PersonElement(root, "author", feed.get("author_detail"))
开发者ID:DeCarabas,项目名称:feedarchive,代码行数:31,代码来源:feedwriter.py

示例2: GetFeedElement

# 需要导入模块: from elementtree.ElementTree import SubElement [as 别名]
# 或者: from elementtree.ElementTree.SubElement import attrib["term"] [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.
    """

    root = Element("feed")
    root.attrib["xmlns"] = "http://www.w3.org/2005/Atom"

    TextElement(root, "title", feed.feed.get("title_detail"))
    if feed.feed.has_key("links"):
        for link in feed.feed.links:
            LinkElement(root, "link", link)
            
    TextElement(root, "subtitle", feed.feed.get("subtitle_detail"))
    TextElement(root, "rights", feed.feed.get("rights_detail"))
    SubElement(root, "generator").text = "feedarchive"
    SubElement(root, "updated").text = rfc3339(time.time())
    SubElementIf(root, "id", feed.feed.get("id"))
    
    if feed.feed.has_key("image"):
        SubElement(root, "icon").text = feed.feed.image.href

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

    PersonElement(root, "author", feed.feed.get("author_detail"))

    for entry in feed.entries:
        ee = SubElement(root, "entry")
        TextElement(ee, "title", entry.get("title_detail"))
        if entry.has_key("links"):
            for link in entry.links:
                LinkElement(ee, "link", link)
        TextElement(ee, "summary", entry.get("summary_detail"))
        TextElement(ee, "content", entry.get("content_detail"))
        DateTimeElement(ee, "published", entry, "published")
        DateTimeElement(ee, "updated", entry, "updated")
        SubElementIf(ee, "id", entry.get("id"))
        PersonElement(ee, "author", entry.get("author_detail"))
        PersonElement(ee, "publisher", entry.get("publisher_detail"))
        if entry.has_key("contributors"):
            for contributor in entry.contributors:
                PersonElement(ee, "contributor", contributor)
        CreateSourceElement(ee, entry.get("source"))

    return root
开发者ID:DeCarabas,项目名称:feedarchive,代码行数:53,代码来源:feedwriter.py


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