[cookboob] comments objectified
This commit is contained in:
parent
34a7c25cef
commit
e6fe9ed69e
4 changed files with 38 additions and 20 deletions
|
|
@ -18,7 +18,7 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# 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.capabilities.base import NotAvailable, NotLoaded
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
|
|
||||||
|
|
@ -121,10 +121,13 @@ class RecipePage(BasePage):
|
||||||
comtxt = unicode(' '.join(divcom.text_content().strip().split()))
|
comtxt = unicode(' '.join(divcom.text_content().strip().split()))
|
||||||
if u'| Répondre' in comtxt:
|
if u'| Répondre' in comtxt:
|
||||||
comtxt = comtxt.strip('0123456789').replace(u' | Répondre', '')
|
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')
|
links_author = self.parser.select(self.document.getroot(), 'p.auteur a.couleur_membre')
|
||||||
print links_author[0].text.strip()
|
|
||||||
if len(links_author) > 0:
|
if len(links_author) > 0:
|
||||||
author = unicode(links_author[0].text.strip())
|
author = unicode(links_author[0].text.strip())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# 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.capabilities.base import NotAvailable, NotLoaded
|
||||||
from weboob.tools.browser import BasePage
|
from weboob.tools.browser import BasePage
|
||||||
|
|
||||||
|
|
@ -123,12 +123,9 @@ class RecipePage(BasePage):
|
||||||
for divcom in self.parser.select(self.document.getroot(), 'div.comment'):
|
for divcom in self.parser.select(self.document.getroot(), 'div.comment'):
|
||||||
author = unicode(self.parser.select(
|
author = unicode(self.parser.select(
|
||||||
divcom, 'div.commentAuthor span', 1).text)
|
divcom, 'div.commentAuthor span', 1).text)
|
||||||
date = unicode(self.parser.select(
|
|
||||||
divcom, 'div.commentDate', 1).text)
|
|
||||||
comtxt = unicode(self.parser.select(
|
comtxt = unicode(self.parser.select(
|
||||||
divcom, 'p', 1).text_content().strip())
|
divcom, 'p', 1).text_content().strip())
|
||||||
comments.append('author: %s, date: %s, text: %s' % (
|
comments.append(Comment(author=author, text=comtxt))
|
||||||
author, date, comtxt))
|
|
||||||
|
|
||||||
spans_author = self.parser.select(self.document.getroot(), 'span.author')
|
spans_author = self.parser.select(self.document.getroot(), 'span.author')
|
||||||
if len(spans_author) > 0:
|
if len(spans_author) > 0:
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# 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.capabilities.base import NotAvailable, NotLoaded
|
||||||
from weboob.tools.browser import BasePage
|
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()
|
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()
|
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()
|
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 = Recipe(id, title)
|
||||||
recipe.preparation_time = preparation_time
|
recipe.preparation_time = preparation_time
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,22 @@ import base64, re, urllib
|
||||||
__all__ = ['Recipe', 'ICapRecipe']
|
__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):
|
class Recipe(CapBaseObject):
|
||||||
"""
|
"""
|
||||||
Recipe object.
|
Recipe object.
|
||||||
|
|
@ -117,17 +133,19 @@ class Recipe(CapBaseObject):
|
||||||
ratings = ET.SubElement(recipe, 'krecipes-ratings')
|
ratings = ET.SubElement(recipe, 'krecipes-ratings')
|
||||||
for c in self.comments:
|
for c in self.comments:
|
||||||
rating = ET.SubElement(ratings, 'rating')
|
rating = ET.SubElement(ratings, 'rating')
|
||||||
com = ET.SubElement(rating, 'comment')
|
if c.author:
|
||||||
com.text = c
|
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')
|
crits = ET.SubElement(rating, 'criterion')
|
||||||
crit = ET.SubElement(crits, 'criteria')
|
if c.rate:
|
||||||
critname = ET.SubElement(crit, 'name')
|
crit = ET.SubElement(crits, 'criteria')
|
||||||
critname.text = ''
|
critname = ET.SubElement(crit, 'name')
|
||||||
critstars = ET.SubElement(crit, 'stars')
|
critname.text = 'Overall'
|
||||||
critstars.text = ''
|
critstars = ET.SubElement(crit, 'stars')
|
||||||
|
critstars.text = c.rate.split('/')[0]
|
||||||
rater = ET.SubElement(rating, 'rater')
|
|
||||||
rater.text = ''
|
|
||||||
|
|
||||||
return header + ET.tostring(doc, encoding='UTF-8', pretty_print=True).decode('utf-8')
|
return header + ET.tostring(doc, encoding='UTF-8', pretty_print=True).decode('utf-8')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue