feedgenerator: code finished

This commit is contained in:
Lars Kiesow 2013-05-03 14:19:04 +02:00
parent 222f3932be
commit 4676cb4d0a
3 changed files with 24 additions and 1 deletions

View file

@ -71,6 +71,7 @@ if __name__ == '__main__':
fg.itunes_new_feed_url('http://example.com/new-feed.rss')
fg.itunes_owner('John Doe', 'john@example.com')
fg.itunes_summary('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Verba tu fingas et ea dicas, quae non sentias?')
fe.itunes_author('Lars Kiesow')
print fg.podcast_str(pretty=True)
elif arg.endswith('atom'):

View file

@ -137,6 +137,8 @@ class FeedEntry(object):
rights = etree.SubElement(feed, 'rights')
rights.text = self.__atom_rights
return entry
def rss_entry(self, feed):
'''Insert an RSS item into a existing XML structure. Normally you
@ -180,6 +182,7 @@ class FeedEntry(object):
pubDate = etree.SubElement(channel, 'pubDate')
pubDate.text = self.__rss_pubDate.strftime(
'%a, %e %b %Y %H:%M:%S %z')
return entry

View file

@ -16,6 +16,7 @@ from datetime import datetime
import dateutil.parser
import dateutil.tz
from feedgenerator.feed import FeedGenerator
from feedgenerator.podcast_entry import PodcastEntry
from feedgenerator.util import ensure_format
@ -44,8 +45,8 @@ class PodcastGenerator(FeedGenerator):
:returns: Tuple containing the feed root element and the element tree.
'''
rss_feed, _ = super(PodcastGenerator,self)._create_rss()
# Replace the root element to add the itunes namespace
ITUNES_NS = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
# Replace the root element to add the itunes namespace
feed = etree.Element('rss', version='2.0',
nsmap={
'atom' :'http://www.w3.org/2005/Atom',
@ -69,6 +70,10 @@ class PodcastGenerator(FeedGenerator):
subcategory = etree.SubElement(category, '{%s}category' % ITUNES_NS)
subcategory.attrib['text'] = self.__itunes_category['sub']
if self.__itunes_image:
image = etree.SubElement(channel, '{%s}image' % ITUNES_NS)
image.text = self.__itunes_image
if self.__itunes_explicit in ('yes', 'no', 'clean'):
explicit = etree.SubElement(channel, '{%s}explicit' % ITUNES_NS)
explicit.text = self.__itunes_explicit
@ -307,6 +312,20 @@ class PodcastGenerator(FeedGenerator):
return self.__itunes_summary
def add_entry(self, podcastEntry=None):
'''This method will add a new entry to the podcast. If the podcastEntry
argument is omittet a new PodcstEntry object is created automatically.
This is the prefered way to add new entries to a feed.
:param podcastEntry: PodcastEntry object to add.
:returns: PodcastEntry object created or passed to this function.
'''
if podcastEntry is None:
podcastEntry = PodcastEntry()
super(PodcastGenerator, self).add_entry( podcastEntry )
return podcastEntry
_itunes_categories = {
'Arts': [ 'Design', 'Fashion & Beauty', 'Food', 'Literature',
'Performing Arts', 'Visual Arts' ],