Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Julien Veyssier
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# 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.capabilities.recipe import Recipe, Comment
from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.tools.browser import BasePage
__all__ = ['RecipePage', 'ResultsPage', 'FourOFourPage']
class FourOFourPage(BasePage):
pass
class ResultsPage(BasePage):
""" Page which contains results as a list of recipies
"""
def iter_recipes(self):
for div in self.parser.select(self.document.getroot(), 'div.recipe-info'):
thumbnail_url = NotAvailable
short_description = NotAvailable
imgs = self.parser.select(div.getparent(), 'img')
if len(imgs) > 0:
url = unicode(imgs[0].attrib.get('src', ''))
if url.startswith('http://'):
thumbnail_url = url
link = self.parser.select(div, 'a.title', 1)
title = unicode(link.text)
id = unicode(link.attrib.get('href', '').split('/')[2])
recipe = Recipe(id, title)
recipe.thumbnail_url = thumbnail_url
recipe.short_description = short_description
recipe.instructions = NotLoaded
recipe.ingredients = NotLoaded
recipe.nb_person = NotLoaded
recipe.cooking_time = NotLoaded
recipe.preparation_time = NotLoaded
recipe.author = NotLoaded
yield recipe
class RecipePage(BasePage):
""" Page which contains a recipe
"""
def get_recipe(self, id):
title = NotAvailable
preparation_time = NotAvailable
cooking_time = NotAvailable
author = NotAvailable
nb_person = NotAvailable
ingredients = NotAvailable
picture_url = NotAvailable
instructions = NotAvailable
comments = []
title = unicode(self.parser.select(self.document.getroot(), 'h1#itemTitle', 1).text)
imgillu = self.parser.select(self.document.getroot(), 'img#imgPhoto')
if len(imgillu) > 0:
picture_url = unicode(imgillu[0].attrib.get('src', ''))
ingredients = []
l_ing = self.parser.select(self.document.getroot(), 'li#liIngredient')
for ing in l_ing:
ingtxt = unicode(ing.text_content().strip())
if ingtxt != '':
ingredients.append(ingtxt)
instructions = u''
l_divinst = self.parser.select(self.document.getroot(), 'div.directLeft li')
num_instr = 1
for inst in l_divinst:
instructions += '%s: %s\n' % (num_instr, inst.text_content())
num_instr += 1
emprep = self.parser.select(self.document.getroot(), 'span#prepMinsSpan em')
if len(emprep) > 0:
preparation_time = int(emprep[0].text)
emcooktime = self.parser.select(self.document.getroot(), 'span#cookMinsSpan em')
if len(emcooktime) > 0:
cooking_time = int(emcooktime[0].text)
l_nbpers = self.parser.select(self.document.getroot(), 'span#lblYield[itemprop=recipeYield]')
if len(l_nbpers) > 0:
nb_person = int(l_nbpers[0].text.split()[0])
recipe = Recipe(id, title)
recipe.preparation_time = preparation_time
recipe.cooking_time = cooking_time
recipe.nb_person = nb_person
recipe.ingredients = ingredients
recipe.instructions = instructions
recipe.picture_url = picture_url
recipe.comments = comments
recipe.author = author
recipe.thumbnail_url = NotLoaded
return recipe