Commit e5aacc04 authored by Bezleputh's avatar Bezleputh Committed by hydrargyrum
Browse files

[cuisineaz] fix module website got updated

parent a1a96b50
......@@ -30,14 +30,25 @@ class CuisineazBrowser(PagesBrowser):
search = URL('recettes/recherche_v2.aspx\?recherche=(?P<pattern>.*)', ResultsPage)
recipe = URL('recettes/(?P<_id>.*).aspx', RecipePage)
search = URL(r'recettes/recherche_terme.aspx\?recherche=(?P<pattern>.*)', ResultsPage)
recipe = URL('recettes/(?P<id>.*).aspx', RecipePage)
def iter_recipes(self, pattern):
return' ', '-')).iter_recipes()
def get_recipe(self, _id, obj=None):
return self.recipe.go(_id=_id).get_recipe(obj=obj)
def get_comments(self, _id):
return self.recipe.stay_or_go(_id=_id).get_comments()
def get_recipe(self, url, obj=None):
assert self.recipe.is_here()
recipe =
recipe.comments = list(self.get_comments(url))
return recipe
def get_comments(self, url):
if not self.recipe.is_here():
assert self.recipe.is_here()
assert self.recipe.is_here()
......@@ -19,19 +19,12 @@
from woob.capabilities.recipe import CapRecipe, Recipe
from import Module
from import unicode
from .browser import CuisineazBrowser
import unicodedata
__all__ = ['CuisineazModule']
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
class CuisineazModule(Module, CapRecipe):
NAME = 'cuisineaz'
MAINTAINER = u'Julien Veyssier'
......@@ -45,9 +38,7 @@ def get_recipe(self, id):
return self.browser.get_recipe(id)
def iter_recipes(self, pattern):
# the search form does that so the url is clean of special chars
# we go directly on search results by the url so we strip it too
return self.browser.iter_recipes(strip_accents(unicode(pattern)))
return self.browser.iter_recipes(pattern)
def fill_recipe(self, recipe, fields):
if 'nb_person' in fields or 'instructions' in fields:
......@@ -17,16 +17,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this woob module. If not, see <>.
from woob.capabilities.recipe import Recipe, Comment
from woob.capabilities.base import NotAvailable
from woob.capabilities.image import BaseImage, Thumbnail
from woob.browser.pages import HTMLPage, pagination
from woob.browser.elements import ItemElement, method, ListElement
from woob.browser.filters.html import XPath
from woob.browser.filters.json import Dict
from woob.capabilities.recipe import Recipe, Comment
from woob.capabilities.image import BaseImage, Thumbnail
from woob.browser.filters.standard import (
CleanText, Regexp, Env, Time, Join, Format, Eval,
from woob.browser.filters.html import XPath
from import json
import re
import datetime
......@@ -34,8 +35,8 @@
class CuisineazDuration(Time):
klass = datetime.timedelta
_regexp = re.compile(r'((?P<hh>\d+) h)?((?P<mm>\d+) min)?(?P<ss>\d+)?')
kwargs = {'hours': 'hh', 'minutes': 'mm', 'seconds': 'ss'}
_regexp = re.compile(r'PT((?P<hh>\d+)H)?((?P<mm>\d+)M)?')
kwargs = {'hours': 'hh', 'minutes': 'mm'}
class ResultsPage(HTMLPage):
......@@ -85,39 +86,41 @@ class RecipePage(HTMLPage):
class get_recipe(ItemElement):
klass = Recipe
obj_id = Env('_id')
obj_title = CleanText('//h1')
def parse(self, el):
items = XPath(u'//script[@type="application/ld+json"]')(self)
for item in items:
content = json.loads(CleanText(u'.')(item))
for el in content:
if el['@type'] == "Recipe":
self.el = el
obj_id = Env('id')
obj_title = Dict('name')
obj_ingredients = Dict('recipeIngredient')
class obj_picture(ItemElement):
klass = BaseImage
obj_url = Format('http:%s',
CleanText('//img[@id="shareimg" and @src!=""]/@src', default=None))
def obj_url(self):
url = Dict('image', default='')(self)
return url[0] if url else url
obj_thumbnail = Eval(Thumbnail, obj_url)
def validate(self, obj):
return obj.url != 'http:'
obj_instructions = Join('\n\n - ', Dict('recipeInstructions'),
addBefore=' - ')
def obj_preparation_time(self):
_prep = CuisineazDuration(CleanText('//span[@id="ContentPlaceHolder_LblRecetteTempsPrepa"]'))(self)
return int(_prep.total_seconds() / 60)
duration = CuisineazDuration(Dict('prepTime'))(self)
return int(duration.total_seconds() / 60)
def obj_cooking_time(self):
_cook = CuisineazDuration(CleanText('//span[@id="ContentPlaceHolder_LblRecetteTempsCuisson"]'))(self)
return int(_cook.total_seconds() / 60)
duration = CuisineazDuration(Dict('cookTime'))(self)
return int(duration.total_seconds() / 60)
def obj_nb_person(self):
nb_pers = CleanText('//span[@id="ContentPlaceHolder_LblRecetteNombre"]')(self)
return [nb_pers] if nb_pers else NotAvailable
def obj_ingredients(self):
ingredients = []
for el in XPath('//section[has-class("recipe_ingredients")]/ul/li')(self):
return ingredients
obj_instructions = Join('\n\n - ', '//div[@id="preparation"]/span/p/text()',
addBefore=' - ')
return [Dict('recipeYield')(self)]
class get_comments(ListElement):
......@@ -126,10 +129,9 @@ class get_comments(ListElement):
class item(ItemElement):
klass = Comment
obj_author = CleanText('./div/div/div/div[@class="author"]')
obj_author = CleanText('./div[@class="author"]')
obj_text = CleanText('./div/div/p')
obj_id = CleanText('./@id')
obj_text = CleanText('./p')
def obj_rate(self):
return len(XPath('.//div/div/div/div/div[@class="icon-star"]')(self))
return len(XPath('./div/div/div[@class="icon-star"]')(self))
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