Re: AllRecipes plugin

View: New views
1 Messages — Rating Filter:   Alert me  

Re: AllRecipes plugin

by Thomas Mills Hinkle-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


 
I've been working on a webpage-importer for AllRecipes.com and think I am getting a real hang for it. I don't have access to the internet all of the time so I haven't been able to test it. The only part I am struggling with is grabbing the servings, and I wasn't sure weather or not to leave the web parser in at the end...
If anyone would like to take a look at it, it is attached.

I've attached a cleaned up version. This works pretty much perfectly for the recipe I've tested. If you're up for some additional testing and refining, I think we could go ahead and include this.

Tom
 
 
--
Knox
 
"I am always doing what I cannot do yet, in order to learn how to do it."
— Vincent Van Gogh
 

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel



[allrecipes_plugin.py]

from gourmet.plugin import PluginPlugin
import re

class AllRecipesPlugin (PluginPlugin):
    target_pluggable = 'webimport_plugin'

    def do_activate (self, pluggable):
        pass
   
    def test_url (self, url, data):
        if 'allrecipes.com' in url:
            return 5

    def get_importer (self, webpage_importer):
        class All_Recipes_Parser (webpage_importer.MenuAndAdStrippingWebParser):
            def preparse (self):
                webpage_importer.MenuAndAdStrippingWebParser.preparse(self)
                #Title
                for title_element in self.soup('h1',{'id':'itemTitle'}):
                    self.preparsed_elements.append((title_element,'title'))
                #Ingredients    <div class="recipe centercontent2">, li
                for recipe in self.soup('div',{'class':'recipe centercontent2'}):
                    bulk = []
                    bulk.append(recipe('li'))
                    self.preparsed_elements.append((bulk[0],'ingredients'))
                    #Directions     div class="recipe centercontent2", li
                    self.preparsed_elements.append((bulk[2],'directions'))
                    #Servings      
                    #div class="recipe centercontent2",<input name="ctl00$CenterColumnPlaceHolder$txtConversion" type="text" value="9"
                    #or
                    #<div id="nutri-info">, 1st p
                    #self.soup('span',{'class':'yield'})
                    #Cook Time
                    for c_time in self.soup('tr',{'id':"ctl00_CenterColumnPlaceHolder_rowCook"}):
                        self.preparsed_elements.append((c_time('b'),'cooktime'))
                    #Prep Time      tr id="ctl00_CenterColumnPlaceHolder_rowPrep", b
                    for element in self.soup('tr',{'id':"ctl00_CenterColumnPlaceHolder_rowPrep"}):
                        self.preparsed_elements.append((element('b'),'preptime'))
                for to_ignore in ['review-block','nutri-div','modal','rb-grey','rvr-grey',
                                  'left','right','modal-upload-a-photo','modal-content',
                                  'modal userWhoSaved','saved custom','recipe-tools-container',
                                  'midpagetabs']:
                    for div in self.soup('div',{'class':to_ignore}):
                        self.preparsed_elements.append((div,'ignore'))
                for to_ignore in ['countries','ctl00_divModal','country','rb','copyright',]:
                    for div in self.soup('div',{'id':to_ignore}):
                        self.preparsed_elements.append((div,'ignore'))
               

        return All_Recipes_Parser


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Grecipe-manager-devel mailing list
Grecipe-manager-devel@...
https://lists.sourceforge.net/lists/listinfo/grecipe-manager-devel