diff --git a/modules/750g/pages.py b/modules/750g/pages.py index 6f63b4b3e7a1bb77e8d4ddb2d812c7488d38e2b5..c81f0577d2d9025e707a070414a3d448082395ae 100644 --- a/modules/750g/pages.py +++ b/modules/750g/pages.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.capabilities.recipe import Recipe +from weboob.capabilities.recipe import Recipe, Comment from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.tools.browser import BasePage @@ -121,10 +121,13 @@ def get_recipe(self, id): comtxt = unicode(' '.join(divcom.text_content().strip().split())) if u'| RĂ©pondre' in comtxt: comtxt = comtxt.strip('0123456789').replace(u' | RĂ©pondre', '') - comments.append(comtxt) + author = None + if 'par ' in comtxt: + author = comtxt.split('par ')[-1].split('|')[0] + comtxt = comtxt.replace('par %s' % author, '') + comments.append(Comment(text=comtxt, author=author)) links_author = self.parser.select(self.document.getroot(), 'p.auteur a.couleur_membre') - print links_author[0].text.strip() if len(links_author) > 0: author = unicode(links_author[0].text.strip()) diff --git a/modules/cuisineaz/pages.py b/modules/cuisineaz/pages.py index 38c37213270b09d618a209395288d82920dd9179..beda21d2f9581cb1e13a87752968b3d33fe5b97d 100644 --- a/modules/cuisineaz/pages.py +++ b/modules/cuisineaz/pages.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.capabilities.recipe import Recipe +from weboob.capabilities.recipe import Recipe, Comment from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.tools.browser import BasePage @@ -123,12 +123,9 @@ def get_recipe(self, id): for divcom in self.parser.select(self.document.getroot(), 'div.comment'): author = unicode(self.parser.select( divcom, 'div.commentAuthor span', 1).text) - date = unicode(self.parser.select( - divcom, 'div.commentDate', 1).text) comtxt = unicode(self.parser.select( divcom, 'p', 1).text_content().strip()) - comments.append('author: %s, date: %s, text: %s' % ( - author, date, comtxt)) + comments.append(Comment(author=author, text=comtxt)) spans_author = self.parser.select(self.document.getroot(), 'span.author') if len(spans_author) > 0: diff --git a/modules/marmiton/pages.py b/modules/marmiton/pages.py index 20812b23a1a9107079ff37a003dcbef6ae43af73..8ea6eaf3b59fdd2d0d359d090f3e5c15a620f83d 100644 --- a/modules/marmiton/pages.py +++ b/modules/marmiton/pages.py @@ -18,7 +18,7 @@ # along with weboob. If not, see . -from weboob.capabilities.recipe import Recipe +from weboob.capabilities.recipe import Recipe, Comment from weboob.capabilities.base import NotAvailable, NotLoaded from weboob.tools.browser import BasePage @@ -91,7 +91,7 @@ def get_recipe(self, id): note = self.parser.select(divcom, 'div.m_commentaire_note span', 1).text.strip() user = self.parser.select(divcom, 'div.m_commentaire_content span', 1).text.strip() content = self.parser.select(divcom, 'div.m_commentaire_content p', 1).text.strip() - comments.append(u'user: %s, note: %s, comment: %s' % (user, note, content)) + comments.append(Comment(author=user, rate=note, text=content)) recipe = Recipe(id, title) recipe.preparation_time = preparation_time diff --git a/weboob/capabilities/recipe.py b/weboob/capabilities/recipe.py index 88d612705ebab9c319d207f21daffa1d26b6cd02..261e06cd2b5bd4fab0027dfa0ce1606f12514198 100644 --- a/weboob/capabilities/recipe.py +++ b/weboob/capabilities/recipe.py @@ -26,6 +26,22 @@ __all__ = ['Recipe', 'ICapRecipe'] +class Comment(): + def __init__(self, author=None, rate=None, text=None): + self.author = author + self.rate = rate + self.text = text + + def __str__(self): + result = u'' + if self.author: + result += 'author: %s, ' % self.author + if self.rate: + result += 'note: %s, ' % self.rate + if self.text: + result += 'comment: %s' % self.text + return result + class Recipe(CapBaseObject): """ Recipe object. @@ -117,17 +133,19 @@ def toKrecipesXml(self, author=None): ratings = ET.SubElement(recipe, 'krecipes-ratings') for c in self.comments: rating = ET.SubElement(ratings, 'rating') - com = ET.SubElement(rating, 'comment') - com.text = c + if c.author: + rater = ET.SubElement(rating, 'rater') + rater.text = c.author + if c.text: + com = ET.SubElement(rating, 'comment') + com.text = c.text crits = ET.SubElement(rating, 'criterion') - crit = ET.SubElement(crits, 'criteria') - critname = ET.SubElement(crit, 'name') - critname.text = '' - critstars = ET.SubElement(crit, 'stars') - critstars.text = '' - - rater = ET.SubElement(rating, 'rater') - rater.text = '' + if c.rate: + crit = ET.SubElement(crits, 'criteria') + critname = ET.SubElement(crit, 'name') + critname.text = 'Overall' + critstars = ET.SubElement(crit, 'stars') + critstars.text = c.rate.split('/')[0] return header + ET.tostring(doc, encoding='UTF-8', pretty_print=True).decode('utf-8')