Commit e6fe9ed6 authored by Julien Veyssier's avatar Julien Veyssier Committed by Florent Fourcot

[cookboob] comments objectified

parent 34a7c25c
......@@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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 @@ class RecipePage(BasePage):
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())
......
......@@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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 @@ class RecipePage(BasePage):
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:
......
......@@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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 @@ class RecipePage(BasePage):
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
......
......@@ -26,6 +26,22 @@ import base64, re, urllib
__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 @@ class Recipe(CapBaseObject):
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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment