fix bugs in marmiton and 750g

This commit is contained in:
Bezleputh 2015-01-21 09:56:31 +01:00 committed by Romain Bignon
commit c4fc3df50a
6 changed files with 23 additions and 15 deletions

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.browser.exceptions import BrowserHTTPNotFound
from weboob.browser import PagesBrowser, URL
from .pages import RecipePage, ResultsPage
@ -35,8 +35,11 @@ class SevenFiftyGramsBrowser(PagesBrowser):
return self.search.go(pattern=pattern.replace(' ', '_')).iter_recipes()
def get_recipe(self, id, recipe=None):
recipe = self.recipe.go(id=id).get_recipe(obj=recipe)
comments = list(self.page.get_comments())
if comments:
recipe.comments = comments
return recipe
try:
recipe = self.recipe.go(id=id).get_recipe(obj=recipe)
comments = list(self.page.get_comments())
if comments:
recipe.comments = comments
return recipe
except BrowserHTTPNotFound:
return

View file

@ -20,6 +20,7 @@
from weboob.tools.test import BackendTest
import itertools
class SevenFiftyGramsTest(BackendTest):
MODULE = '750g'

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.browser.exceptions import BrowserHTTPNotFound
from weboob.browser import PagesBrowser, URL
from .pages import RecipePage, ResultsPage
@ -35,8 +35,11 @@ class MarmitonBrowser(PagesBrowser):
return self.search.go(pattern=pattern).iter_recipes()
def get_recipe(self, id, recipe=None):
recipe = self.recipe.go(id=id).get_recipe(obj=recipe)
comments = list(self.page.get_comments())
if comments:
recipe.comments = comments
return recipe
try:
recipe = self.recipe.go(id=id).get_recipe(obj=recipe)
comments = list(self.page.get_comments())
if comments:
recipe.comments = comments
return recipe
except BrowserHTTPNotFound:
return

View file

@ -43,7 +43,7 @@ class MarmitonModule(Module, CapRecipe):
return self.browser.iter_recipes(quote_plus(pattern.encode('utf-8')))
def fill_recipe(self, recipe, fields):
if 'nb_person' in fields or 'instructions' in fields:
if 'nb_person' in fields or 'instructions' in fields or 'thumbnail_url' in fields:
recipe = self.browser.get_recipe(recipe.id, recipe)
return recipe

View file

@ -42,7 +42,6 @@ class ResultsPage(HTMLPage):
obj_id = Regexp(CleanText('./div/div[@class="m_titre_resultat"]/a/@href'),
'/recettes/recette_(.*).aspx')
obj_title = CleanText('./div/div[@class="m_titre_resultat"]/a')
obj_thumbnail_url = CleanText('./a[@class="m_resultat_lien_image"]', default='')
obj_short_description = Format('%s. %s',
CleanText('./div/div[@class="m_detail_recette"]'),
CleanText('./div/div[@class="m_texte_resultat"]'))
@ -71,7 +70,8 @@ class RecipePage(HTMLPage):
return ingredients[1:]
obj_instructions = CleanHTML('//div[@class="m_content_recette_todo"]')
obj_picture_url = CleanText('//a[@class="m_content_recette_illu"]/@href', default=NotAvailable)
obj_thumbnail_url = CleanText('//a[@class="m_content_recette_illu"]/img/@src', default=NotAvailable)
obj_picture_url = CleanText('//a[@class="m_content_recette_illu"]/img/@src', default=NotAvailable)
@method
class get_comments(ListElement):

View file

@ -20,6 +20,7 @@
from weboob.tools.test import BackendTest
import itertools
class MarmitonTest(BackendTest):
MODULE = 'marmiton'