Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 01-17-2010, 05:32 PM   #1
BrianG
Member
BrianG began at the beginning.
 
Posts: 23
Karma: 22
Join Date: Dec 2009
Device: Kindle DX
"Virtual" feed method

I've been working on a recipe (Reader's Digest) with a big comprehensive RSS feed in it. I was getting annoyed that there were lots of recipe articles (the food recipes, not the Calibre ones) mixed into the main feed along with the "real" stories.

It took a while to get my head around the Feed and Article types in BasicRecipe, but I was able to write a PARSE_FEEDS that scans thru the existing feeds and then creats a separate TOC section for any article that contains the word "Recipe". Here's an example of what it does after normal feed retrieval:


As-is looks like:
Main Feed
Article a
Recipe a
Recipe b
Article b

New looks like:
Main Feed
Article a
Article b
Recipes
Recipe a
Recipe b



I have posted the code below. It's certainly not revolutionary, but could be useful for future recipes. Please, no giggling at my lack of Python skills!

BTW: Is there a sticky anywhere for posting reusable recipe code fragments? I'd definitely be interested in seeing what others have already done (without scanning thru all of the existing recipes).


def parse_feeds (self):

# Do the "official" parse_feeds first
feeds = BasicNewsRecipe.parse_feeds(self)


# Loop thru the articles in all feeds to find articles with "recipe" in it
recipeArticles = []
for curfeed in feeds:
delList = []
for a,curarticle in enumerate(curfeed.articles):
if curarticle.title.upper().find('RECIPE') >= 0:
recipeArticles.append(curarticle)
delList.append(curarticle)
if len(delList)>0:
for d in delList:
index = curfeed.articles.index(d)
curfeed.articles[index:index+1] = []

# If there are any recipes found, create/append a new Feed object if len(recipeArticles) > 0:
pfeed = Feed()
pfeed.title = 'Recipes'
pfeed.descrition = 'Recipe Feed (Virtual)'
pfeed.image_url = None
pfeed.oldest_article = 30
pfeed.id_counter = len(recipeArticles)
# Create a new Feed, add the recipe articles, and append
# to "official" list of feeds
pfeed.articles = recipeArticles[:]
feeds.append(pfeed)

return feeds
BrianG is offline   Reply With Quote
Old 01-17-2010, 08:29 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Looks fine. There isn't such a thread as how would it be organized?
kovidgoyal is online now   Reply With Quote
Advert
Old 01-17-2010, 10:56 PM   #3
BrianG
Member
BrianG began at the beginning.
 
Posts: 23
Karma: 22
Join Date: Dec 2009
Device: Kindle DX
I would have seen the thread as a free-for-all sticky called "Code for re-use". It would include modules along with a brief explanation of purpose...
BrianG is offline   Reply With Quote
Old 01-18-2010, 12:00 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Feel free to start one
kovidgoyal is online now   Reply With Quote
Old 01-18-2010, 06:46 AM   #5
DoctorOhh
US Navy, Retired
DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.
 
DoctorOhh's Avatar
 
Posts: 9,864
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Nexus 7
Quote:
Originally Posted by BrianG View Post
I would have seen the thread as a free-for-all sticky called "Code for re-use". It would include modules along with a brief explanation of purpose...
Code:
I am ignorant about coding these
recipes and would welcome a thread
of this sort.   However if you do decide to
start a thread set a good example by placing
your code inside code tags.  This way the 
spaces / format of the code stay in tact.
...
Good Idea.
DoctorOhh is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Settings," then "311" - Int'l Kindle searches for wireless providers in the area Dr. Drib Amazon Kindle 2 08-28-2011 10:27 AM
Yep. It's official. Sony Reader has "ruined" books for me. A final "review." WilliamG Sony Reader 48 01-14-2011 03:49 AM
Continuing the "virtual visit to old things" theme ardeegee Lounge 1 05-08-2010 05:00 PM
"get feed": max length alexxxm Sony Reader 1 01-21-2008 12:56 PM
SciFi novel "Synergy" goes on a virtual tour Alexander Turcic News 0 03-21-2007 06:06 PM


All times are GMT -4. The time now is 04:25 AM.


MobileRead.com is a privately owned, operated and funded community.