Exemple #1
0
 def write_attr(self, label, text):
     attr = gglobals.NAME_TO_ATTR.get(label, label)
     if attr == 'title':
         self.txt.append(Bookmark(self.r.title, 'r' + str(self.r.id)))
         self.write_paragraph(text, style=self.styleSheet['Heading1'])
         return
     if attr == 'rating':
         from gourmet.importers.importer import string_to_rating
         val = string_to_rating(text)
         if val:
             self.attributes.append(self.make_rating(label, val))
             return
     if attr == 'link':
         trimmed = text.strip()
         if len(trimmed) > 32:
             trimmed = trimmed[:29] + '…'  # ellipsis dots
         self.attributes.append(
             self.make_paragraph('%s: <link href="%s">%s</link>' %
                                 (label, text, trimmed)))
         return
     if attr == 'source':
         trimmed = text.strip()
         if len(trimmed) > 32:
             trimmed = trimmed[:29] + '&#8230;'  # ellipsis dots
         self.attributes.append(
             self.make_paragraph('%s: %s' % (label, trimmed)))
         return
     # If nothing else has returned...
     self.attributes.append(self.make_paragraph("%s: %s" % (label, text)))
 def write_attr (self, label, text):
     attr = gglobals.NAME_TO_ATTR.get(label,label)
     if attr=='title':
         self.txt.append(Bookmark(self.r.title,'r'+str(self.r.id)))
         self.write_paragraph(text,style=self.styleSheet['Heading1'])
         return
     if attr=='rating':
         from gourmet.importers.importer import string_to_rating
         val = string_to_rating(text)
         if val:
             self.attributes.append(self.make_rating(label,val))
             return
     if attr=='link':
         trimmed = text.strip()
         if len(trimmed)>32:
             trimmed=trimmed[:29]+'&#8230;' # ellipsis dots
         self.attributes.append(self.make_paragraph('%s: <link href="%s">%s</link>'%(label,text,trimmed)))
         return
     if attr=='source':
         trimmed = text.strip()
         if len(trimmed)>32:
             trimmed=trimmed[:29]+'&#8230;' # ellipsis dots
         self.attributes.append(self.make_paragraph('%s: %s'%(label,trimmed)))
         return
     # If nothing else has returned...
     self.attributes.append(self.make_paragraph("%s: %s"%(label,text)))
Exemple #3
0
    def write_attr(self, attr, text):
        #attr mapping
        if (attr == 'link'):
            attr = 'url'
        if (attr == 'category'):
            attr = 'category'
        if (attr == 'servings'):
            attr = 'quantity'
        if (attr == 'cooktime'):
            attr = 'cooktime'
        if (attr == 'preptime'):
            attr = 'preptime'
        if (attr == 'yields'):
            attr = 'quantity'
            text = text.split(' ')[0]  # Remove units if present
        if (attr == 'rating'):
            from gourmet.importers.importer import string_to_rating
            val = string_to_rating(text)
            if val:
                # MyCookbook's rating range is integers from 1 to 5, while
                # ours is from 1 to 10, so we have to floor divide by 2 when
                # exporting.
                self.rec_el.appendChild(
                    self.create_text_element('rating', str(val // 2)))
                return
        if (attr == 'title'):
            self.current_title = text.replace(' ', '_')

        self.rec_el.appendChild(
            self.create_text_element(attr.replace(' ', ''), text))
    def write_attr (self, attr, text):
        #attr mapping
        if (attr == 'link'):
            attr = 'url'
        if (attr == 'category'):
            attr = 'category'
        if (attr == 'servings'):
            attr = 'quantity'
        if (attr == 'cooktime'):
            attr = 'cooktime'
        if (attr == 'preptime'):
            attr = 'preptime'
        if (attr == 'yields'):
            attr = 'quantity'
            text = text.split(' ')[0] # Remove units if present
        if (attr == 'rating'):
            from gourmet.importers.importer import string_to_rating
            val = string_to_rating(text)
            if val:
                # MyCookbook's rating range is integers from 1 to 5, while
                # ours is from 1 to 10, so we have to floor divide by 2 when
                # exporting.
                self.rec_el.appendChild(self.create_text_element('rating', str(val//2)))
                return
        if (attr == 'title'):
            self.current_title = text.replace(' ','_')

        self.rec_el.appendChild(self.create_text_element(attr.replace(' ',''),text))