コード例 #1
0
 def add_ing_from_text (self, txt):
     if not hasattr(self,'db'):
         import gourmet.backends.db as db
         self.db = db.get_database()
     parsed_dict = self.db.parse_ingredient(txt)
     self.ing = parsed_dict
     self.commit_ing()
コード例 #2
0
 def add_ing_from_text(self, txt):
     if not hasattr(self, 'db'):
         import gourmet.backends.db as db
         self.db = db.get_database()
     parsed_dict = self.db.parse_ingredient(txt)
     self.ing = parsed_dict
     self.commit_ing()
コード例 #3
0
ファイル: test_db.py プロジェクト: bunburya/gourmet
 def setUp (self):
     print('Calling setUp')
     # Remove all plugins for testing purposes
     ml = MasterLoader.instance()
     ml.save_active_plugins = lambda *args: True; # Don't save anything we do to plugins
     ml.active_plugins = []
     ml.active_plugin_sets = []
     # Done knocking out plugins...
     tmpfile = tempfile.mktemp()
     self.db = db.get_database(file=tmpfile)
コード例 #4
0
ファイル: test_db.py プロジェクト: sthapa/gourmet
 def setUp(self):
     print('Calling setUp')
     # Remove all plugins for testing purposes
     from gourmet.plugin_loader import get_master_loader
     ml = get_master_loader()
     ml.save_active_plugins = lambda *args: True
     # Don't save anything we do to plugins
     ml.active_plugins = []
     ml.active_plugin_sets = []
     # Done knocking out plugins...
     tmpfile = tempfile.mktemp()
     self.db = db.get_database(file=tmpfile)
コード例 #5
0
 def endElement (self, name):
     key,method=None,None
     if name==self.RECIPE_TAG:
         self.commit_rec()
         return
     if name=='li' and self.current_section=='ingredient':
         if not hasattr(self,'db'):
             import gourmet.backends.db as db
             self.db = db.get_database()
         ingdic = self.db.parse_ingredient(self.elbuf.strip())
         self.start_ing(**ingdic)
         self.commit_ing()
     if name=='li' and self.current_section=='instruction':
         key = 'instructions'
         method = self.ADD
         obj = self.rec
     if name=='li' and self.current_section=='comments':
         key = 'modifications'
         method = self.ADD
         obj = self.rec
     if name == 'imagepath':
         obj = self.rec
         #get the temp directory and build the image path
         (dirname, filename) = os.path.split(self.parent_thread.fn)
         (pic_dirname, pic_filename) = os.path.split(self.elbuf.strip())
         pic_fullpath = os.path.join(dirname,'images',pic_filename)
         
         #try to import the image
         if os.path.isfile(pic_fullpath):
             try:
                 print 'pic_fullpath:'+pic_fullpath
                 im = Image.open(pic_fullpath)
                 obj['image'] = gourmet.ImageExtras.get_string_from_image(im)
                 #obj['image'] = gourmet.ImageExtras.get_string_from_image(gourmet.ImageExtras.resize_image(im,60,60))
             except Exception, e:
                 print 'Issue loading: '+pic_fullpath
                 print str(e)
                 #dont stop if corrupted image file
                 pass
コード例 #6
0
    def endElement(self, name):
        key, method = None, None
        if name == self.RECIPE_TAG:
            self.commit_rec()
            return
        if name == 'li' and self.current_section == 'ingredient':
            if not hasattr(self, 'db'):
                import gourmet.backends.db as db
                self.db = db.get_database()
            ingdic = self.db.parse_ingredient(self.elbuf.strip())
            self.start_ing(**ingdic)
            self.commit_ing()
        if name == 'li' and self.current_section == 'instruction':
            key = 'instructions'
            method = self.ADD
            obj = self.rec
        if name == 'li' and self.current_section == 'comments':
            key = 'modifications'
            method = self.ADD
            obj = self.rec
        if name == 'imagepath':
            obj = self.rec
            #get the temp directory and build the image path
            (dirname, filename) = os.path.split(self.parent_thread.fn)
            (pic_dirname, pic_filename) = os.path.split(self.elbuf.strip())
            pic_fullpath = os.path.join(dirname, 'images', pic_filename)

            #try to import the image
            if os.path.isfile(pic_fullpath):
                try:
                    im = Image.open(pic_fullpath)
                    obj['image'] = gourmet.ImageExtras.get_string_from_image(
                        im)
                    #obj['image'] = gourmet.ImageExtras.get_string_from_image(gourmet.ImageExtras.resize_image(im,60,60))
                except Exception, e:
                    print 'Issue loading: ' + pic_fullpath
                    print str(e)
                    #dont stop if corrupted image file
                    pass
コード例 #7
0
    def endElement(self, name):
        key, method = None, None
        if name == self.RECIPE_TAG:
            self.commit_rec()
            return
        if name == 'li' and self.current_section == 'ingredient':
            if not hasattr(self, 'db'):
                import gourmet.backends.db as db
                self.db = db.get_database()
            ingdic = self.db.parse_ingredient(self.elbuf.strip())
            self.start_ing(**ingdic)
            self.commit_ing()
        if name == 'li' and self.current_section == 'instruction':
            key = 'instructions'
            method = self.ADD
            obj = self.rec
        if name == 'li' and self.current_section == 'comments':
            key = 'modifications'
            method = self.ADD
            obj = self.rec
        if name == 'imagepath':
            obj = self.rec
            #get the temp directory and build the image path
            (dirname, filename) = os.path.split(self.parent_thread.fn)
            (pic_dirname, pic_filename) = os.path.split(self.elbuf.strip())
            pic_fullpath = os.path.join(dirname, 'images', pic_filename)

            #try to import the image
            if os.path.isfile(pic_fullpath):
                try:
                    im = Image.open(pic_fullpath)
                    obj['image'] = gourmet.ImageExtras.get_string_from_image(
                        im)
                    #obj['image'] = gourmet.ImageExtras.get_string_from_image(gourmet.ImageExtras.resize_image(im,60,60))
                except Exception as e:
                    print('Issue loading: ' + pic_fullpath)
                    print(str(e))
                    #dont stop if corrupted image file
                    pass

        # times fixing
        if name == 'cooktime' or name == 'preptime':
            self.elbuf = self.elbuf.replace('mn', 'min')
            if re.match('([0-9]*)min', self.elbuf):
                self.elbuf = self.elbuf.replace('min', ' min')

        #other tags
        if name == self.ING_TAG:
            self.current_section = ''
        elif name == self.INSTR_TAG:
            self.current_section = ''
        elif name == self.COMMENT_TAG:
            self.current_section = ''
        elif name in self.RECTAGS:
            obj = self.rec
            key, method = self.RECTAGS[name]

        if key:
            if key == 'rating':
                # MyCookbook's rating range is integers from 1 to 5, while
                # ours is from 1 to 10, so we have to multiply by 2 when
                # importing.
                obj['rating'] = int(self.elbuf.strip()) * 2
            elif method == self.ADD and key in obj:
                obj[key] = obj[key] + "\n " + self.elbuf
            else:
                obj[key] = self.elbuf