From d391d1a2d8afd6e38b88da5f84d49024d12fd075 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Mon, 25 Mar 2013 02:39:41 +0100 Subject: [PATCH] [cookboob] author field added --- modules/750g/backend.py | 1 + modules/750g/pages.py | 8 ++++++++ modules/cuisineaz/backend.py | 1 + modules/cuisineaz/pages.py | 7 +++++++ modules/marmiton/backend.py | 1 + modules/marmiton/pages.py | 2 ++ weboob/applications/cookboob/cookboob.py | 2 ++ weboob/capabilities/recipe.py | 12 ++++++++++-- 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/modules/750g/backend.py b/modules/750g/backend.py index e888c179..ed2180eb 100644 --- a/modules/750g/backend.py +++ b/modules/750g/backend.py @@ -50,6 +50,7 @@ class SevenFiftyGramsBackend(BaseBackend, ICapRecipe): recipe.instructions = rec.instructions recipe.ingredients = rec.ingredients recipe.comments = rec.comments + recipe.author = rec.author recipe.nb_person = rec.nb_person recipe.cooking_time = rec.cooking_time recipe.preparation_time = rec.preparation_time diff --git a/modules/750g/pages.py b/modules/750g/pages.py index 428078f1..6f63b4b3 100644 --- a/modules/750g/pages.py +++ b/modules/750g/pages.py @@ -61,6 +61,7 @@ class ResultsPage(BasePage): recipe.nb_person = NotLoaded recipe.cooking_time = NotLoaded recipe.preparation_time = NotLoaded + recipe.author = NotLoaded yield recipe @@ -75,6 +76,7 @@ class RecipePage(BasePage): ingredients = NotAvailable picture_url = NotAvailable instructions = NotAvailable + author = NotAvailable comments = [] title = unicode(self.parser.select(self.document.getroot(), 'head > title', 1).text.split(' - ')[1]) @@ -120,6 +122,11 @@ class RecipePage(BasePage): if u'| Répondre' in comtxt: comtxt = comtxt.strip('0123456789').replace(u' | Répondre', '') comments.append(comtxt) + + 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()) recipe = Recipe(id, title) recipe.preparation_time = preparation_time @@ -129,5 +136,6 @@ class RecipePage(BasePage): recipe.instructions = instructions recipe.picture_url = picture_url recipe.comments = comments + recipe.author = author recipe.thumbnail_url = NotLoaded return recipe diff --git a/modules/cuisineaz/backend.py b/modules/cuisineaz/backend.py index a39bde5a..2296f363 100644 --- a/modules/cuisineaz/backend.py +++ b/modules/cuisineaz/backend.py @@ -57,6 +57,7 @@ class CuisineazBackend(BaseBackend, ICapRecipe): recipe.instructions = rec.instructions recipe.ingredients = rec.ingredients recipe.comments = rec.comments + recipe.author = rec.author recipe.nb_person = rec.nb_person recipe.cooking_time = rec.cooking_time recipe.preparation_time = rec.preparation_time diff --git a/modules/cuisineaz/pages.py b/modules/cuisineaz/pages.py index 442f64a1..38c37213 100644 --- a/modules/cuisineaz/pages.py +++ b/modules/cuisineaz/pages.py @@ -70,6 +70,7 @@ class ResultsPage(BasePage): recipe.nb_person = NotLoaded recipe.cooking_time = NotLoaded recipe.preparation_time = NotLoaded + recipe.author = NotLoaded yield recipe @@ -80,6 +81,7 @@ class RecipePage(BasePage): title = NotAvailable preparation_time = NotAvailable cooking_time = NotAvailable + author = NotAvailable nb_person = NotAvailable ingredients = NotAvailable picture_url = NotAvailable @@ -128,6 +130,10 @@ class RecipePage(BasePage): comments.append('author: %s, date: %s, text: %s' % ( author, date, comtxt)) + spans_author = self.parser.select(self.document.getroot(), 'span.author') + if len(spans_author) > 0: + author = unicode(spans_author[0].text_content().strip()) + recipe = Recipe(id, title) recipe.preparation_time = preparation_time recipe.cooking_time = cooking_time @@ -136,5 +142,6 @@ class RecipePage(BasePage): recipe.instructions = instructions recipe.picture_url = picture_url recipe.comments = comments + recipe.author = author recipe.thumbnail_url = NotLoaded return recipe diff --git a/modules/marmiton/backend.py b/modules/marmiton/backend.py index d36b0f32..ab8ef916 100644 --- a/modules/marmiton/backend.py +++ b/modules/marmiton/backend.py @@ -52,6 +52,7 @@ class MarmitonBackend(BaseBackend, ICapRecipe): recipe.instructions = rec.instructions recipe.ingredients = rec.ingredients recipe.comments = rec.comments + recipe.author = rec.author recipe.nb_person = rec.nb_person recipe.cooking_time = rec.cooking_time recipe.preparation_time = rec.preparation_time diff --git a/modules/marmiton/pages.py b/modules/marmiton/pages.py index d1a6a028..20812b23 100644 --- a/modules/marmiton/pages.py +++ b/modules/marmiton/pages.py @@ -49,6 +49,7 @@ class ResultsPage(BasePage): recipe.thumbnail_url = thumbnail_url recipe.short_description = short_description recipe.instructions = NotLoaded + recipe.author = NotLoaded recipe.ingredients = NotLoaded recipe.nb_person = NotLoaded recipe.cooking_time = NotLoaded @@ -101,4 +102,5 @@ class RecipePage(BasePage): recipe.picture_url = picture_url recipe.comments = comments recipe.thumbnail_url = NotLoaded + recipe.author = NotAvailable return recipe diff --git a/weboob/applications/cookboob/cookboob.py b/weboob/applications/cookboob/cookboob.py index f76ac0df..9b3d5ed3 100644 --- a/weboob/applications/cookboob/cookboob.py +++ b/weboob/applications/cookboob/cookboob.py @@ -37,6 +37,8 @@ class RecipeInfoFormatter(IFormatter): def format_obj(self, obj, alias): result = u'%s%s%s\n' % (self.BOLD, obj.title, self.NC) result += 'ID: %s\n' % obj.fullid + if not empty(obj.author): + result += 'Author: %s\n' % obj.author result += 'Preparation time: %smin\n' % obj.preparation_time if not empty(obj.cooking_time): result += 'Cooking time: %smin\n' % obj.cooking_time diff --git a/weboob/capabilities/recipe.py b/weboob/capabilities/recipe.py index 64c2b51c..a58759e9 100644 --- a/weboob/capabilities/recipe.py +++ b/weboob/capabilities/recipe.py @@ -31,6 +31,7 @@ class Recipe(CapBaseObject): Recipe object. """ title = StringField('Title of the recipe') + author = StringField('Author name of the recipe') thumbnail_url = StringField('Direct url to recipe thumbnail') picture_url = StringField('Direct url to recipe picture') short_description = StringField('Short description of a recipe') @@ -49,8 +50,15 @@ class Recipe(CapBaseObject): """ Export recipe to KRecipes XML string """ + sauthor = u'' + if not empty(self.author): + sauthor += '%s@' % self.author + if author == None: - author = 'Cookboob' + sauthor += 'Cookboob' + else: + sauthor += author + header = u'\n' initial_xml = '''\ @@ -63,7 +71,7 @@ class Recipe(CapBaseObject): title = ET.SubElement(desc, 'title') title.text = self.title authors = ET.SubElement(desc, 'author') - authors.text = author + authors.text = sauthor eyield = ET.SubElement(desc, 'yield') if not empty(self.nb_person): amount = ET.SubElement(eyield, 'amount')