示例#1
0
文件: parser.py 项目: Podato/podato
def parse_feed(feed_str):
    """Parses a feed, and returns a Podcast instance"""
    podcast = ParsedPodcast()
    tree = cElementTree.fromstring(feed_str.encode("utf-8"))
    channel = tree[0]

    for child in channel:
        if child.tag == "title":
            podcast.title = child.text
        elif child.tag == "link":
            podcast.link = child.text
        elif child.tag == "description":
            podcast.description = child.text
        elif child.tag == "language":
            podcast.language = child.text
        elif child.tag == "copyright":
            podcast.copyright = child.text
        elif child.tag == ITUNES_NS + "author":
            podcast.author = child.text
        elif child.tag == ITUNES_NS + "keywords":
            podcast.tags += child.text.split(", ")
        elif child.tag == ITUNES_NS + "explicit":
            podcast.explicit = child.text
        elif child.tag == ITUNES_NS + "image":
            podcast.image = child.attrib.get("href")
        elif child.tag == ITUNES_NS + "owner":
            podcast.owner = _parse_person(child)
        elif child.tag == ITUNES_NS + "category":
            podcast.categories += _parse_categories(child)
        elif child.tag == "item":
            podcast.episodes.append(_parse_item(child))

    return podcast
示例#2
0
def create_valid_podcast():
    """Creates a valid podcast."""
    podcast = ParsedPodcast(**TEST_DATA)
    podcast.episodes = map(lambda d: ParsedEpisode(**d), podcast.episodes)
    return podcast