Example #1
0
 def do_run (self):
     recipe = self.parser.parse(self.selector)
     
     if 'imageUrl' in recipe:
         imageUrl = recipe['imageUrl']
         del recipe['imageUrl']
         # TODO: load image from url and attach
         
         r = requests.get(imageUrl)
         if r.status_code == 200 and r.headers['content-type'] == 'image/jpeg':
             recipe["image"] = r.content
             
     if 'link' not in recipe and self.url:
         recipe['link'] = self.url
         
     if 'servings' in recipe:
         # The code doing the translation in importer seems to be in conflict
         # with some database code. if yields and servings is set only servings is
         # written to db
         servs = float(recipe['servings'])
         del recipe['servings']
         recipe['yields'] = servs
         recipe['yield_unit'] = gettext.ngettext('serving', 'servings', servs)
     
     self.start_rec( recipe )
     
     if 'ingredients' in recipe:
         self._add_ingredients( recipe['ingredients'] )
         del recipe['ingredients']
     self.commit_rec()
     
     return ConvenientImporter.do_run(self)
Example #2
0
 def __init__(self, rd):
     ConvenientImporter.__init__(self, rd, threaded=True)
 def __init__ (self, rd):
     ConvenientImporter.__init__(self,rd,threaded=True)
Example #4
0
 def __init__ (self, url, data, parser):
     ConvenientImporter.__init__(self)
     self.parser = parser
     self.selector = Selector(text=data)
     self.url = url