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


Python Element.attrib["version"]方法代码示例

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


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

示例1: GetFeedElement

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

示例2: createFilePodcast

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import attrib["version"] [as 别名]
def createFilePodcast(mediaFilePath, title, description=''):
    """
    create the xml file using utf
    """  
    
    mediaItem = Element("media")    
    mediaItem.attrib["version"] = VERSION
    titleNode = SubElement(mediaItem, "title")
    titleNode.text = title
    descrNode = SubElement(mediaItem, "description")
    descrNode.text = description
    
    createXmlFile(mediaFilePath + '.xml', mediaItem)
    
    mediaItem.clear()
开发者ID:visualtecnologicc,项目名称:mediastream,代码行数:17,代码来源:utils.py

示例3: getPodcastLocalItems

# 需要导入模块: from elementtree.ElementTree import Element [as 别名]
# 或者: from elementtree.ElementTree.Element import attrib["version"] [as 别名]
def getPodcastLocalItems(podcastInfo):
    """
    search in the media dir if the podcast dir already exist, read it, return a reference on the tree!, 
    
    return podcastLocalInfo that include the element root, warning not cleared
    
    """
    
    podcastLocalInfo = PodcastInfo()
    reportList = []
    reportFilename = podcastInfo.targetDirectory + '\\_podcast.xml'
    elemMedia = None
    
    # try to create dir
    #if not createDirectory(podcastInfo.targetDirectory):
    #    raise MyCancel('Exit')
    
    if os.path.exists(reportFilename):
        # real all pathes
        
        file = open(reportFilename, "r")
        tree = parse(file)
        elemMedia = tree.getroot() # 'media'
    
        # get the global info here... maintitle, main description ??? YES
        conf_version = elemMedia.get('version')    
        maintitle = elemMedia.findtext('title', '')                    
        maindescription = elemMedia.findtext('description', '')
        podcastLocalInfo.title = maintitle
        podcastLocalInfo.description = maindescription
    
        for itemNode in elemMedia.getiterator('item'):
            url = itemNode.get('url')
            filename = itemNode.get('filename')
            flagfinish = itemNode.get('isfinished')
            
            title = itemNode.findtext('title', '')                    
            description = itemNode.findtext('description', '')
        
            itemReport = PodcastItem()
            itemReport.url = url
            itemReport.filename = filename
            # init location
            fileLocation = podcastInfo.targetDirectory + '\\' + filename
            itemReport.fileLocation = fileLocation
            itemReport.isLocal = True
            itemReport.flagfinish = flagfinish != None and flagfinish.lower() == 'true'
            itemReport.title = title
            itemReport.description = description
            
            podcastLocalInfo.itemFilenames.append(filename)
            podcastLocalInfo.itemsInfo.append(itemReport)
        
        #elemMedia.clear()
        file.close()
        
        
    else:
        #init the main info
        podcastLocalInfo.title = podcastInfo.title
        podcastLocalInfo.description = podcastInfo.description
                
        elemMedia = Element("media")
        elemMedia.attrib["version"] = VERSION
        
        titleNode = SubElement(elemMedia, "title")
        titleNode.text = podcastLocalInfo.title
        descrNode = SubElement(elemMedia, "description")
        descrNode.text = podcastLocalInfo.description
    
    # add it to the both elements
    podcastInfo.localElementRoot = elemMedia
    
    return podcastLocalInfo
开发者ID:visualtecnologicc,项目名称:mediastream,代码行数:76,代码来源:main.py


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