View Single Post
Old 01-19-2010, 01:05 PM   #3
BrianG
Member
BrianG began at the beginning.
 
Posts: 23
Karma: 22
Join Date: Dec 2009
Device: Kindle DX
Add FEED objects during PARSE_INDEX

There is a slight difference between the Feeds object that is returned from PARSE_FEEDS and the object returned when using PARSE_INDEX.

The module below (FEED_TO_INDEX_APPEND) accepts a Feed object and an Index object. The Feed object is traversed and appended to the Index.

This can be useful in mixing the use of an index as well as RSS feeds in a single recipe. It could be called in a way similar to:

Spoiler:
Code:
	# Do the "official" parse_feeds first
	rssFeeds = Feed()
	rssFeeds = BasicNewsRecipe.parse_feeds(self)

	# Append the rssFeeds object to the feeds list that would be
             # used in PARSE_INDEX
	self.feed_to_index_append(rssFeeds[:], feeds)


Here is the conversion module:

Spoiler:
Code:
   def feed_to_index_append(self, feedObject, masterFeed):

	# Loop thru the feed object and build the correct type of article list
	for feed in feedObject:
		newArticles = []
		for article in feed.articles:
			newArt = {
	                          'title' : article.title,
      	                          'url'   : article.url,
            	                          'date'  : article.date,
                  	              'description' : article.text_summary
				}	

			newArticles.append(newArt)
	
		# append the newly-built list object to the index object 		             # passed in as masterFeed.
		masterFeed.append((feed.title,newArticles))

Last edited by Starson17; 02-25-2011 at 09:07 PM.
BrianG is offline   Reply With Quote