From b967fc4ef8121e536ac19cf7d1e2ef5fc7369899 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sun, 24 Mar 2013 21:21:29 +0100 Subject: [PATCH] [cookboob] integration of recipe picture in exported file --- weboob/capabilities/recipe.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/weboob/capabilities/recipe.py b/weboob/capabilities/recipe.py index df563069..b48ca1fd 100644 --- a/weboob/capabilities/recipe.py +++ b/weboob/capabilities/recipe.py @@ -19,7 +19,9 @@ from .base import IBaseCap, CapBaseObject, StringField, IntField, Field, empty -import xml.etree.ElementTree as ET +import lxml.etree as ET +import base64 +import urllib __all__ = ['Recipe', 'ICapRecipe'] @@ -50,6 +52,7 @@ class Recipe(CapBaseObject): """ if author == None: author = 'Cookboob' + header = u'\n' initial_xml = '''\ @@ -71,6 +74,13 @@ class Recipe(CapBaseObject): if not empty(self.preparation_time): preptime = ET.SubElement(desc, 'preparation-time') preptime.text = '%02d:%02d' % (self.preparation_time / 60, self.preparation_time % 60) + if not empty(self.picture_url): + data = urllib.urlopen(self.picture_url).read() + datab64 = base64.encodestring(data)[:-1] + + pictures = ET.SubElement(desc, 'pictures') + pic = ET.SubElement(pictures, 'pic', {'format' : 'JPEG', 'id' : '1'}) + pic.text = ET.CDATA(datab64) if not empty(self.ingredients): ings = ET.SubElement(recipe, 'krecipes-ingredients') @@ -87,7 +97,7 @@ class Recipe(CapBaseObject): instructions = ET.SubElement(recipe, 'krecipes-instructions') instructions.text = self.instructions - return ET.tostring(doc, encoding='UTF-8').decode('utf-8') + return header + ET.tostring(doc, encoding='UTF-8', pretty_print=True).decode('utf-8') class ICapRecipe(IBaseCap):