new backend marmiton

This commit is contained in:
Julien Veyssier 2013-03-14 20:18:13 +01:00
commit 4798fdd411
8 changed files with 312 additions and 13 deletions

View file

@ -22,16 +22,16 @@ from __future__ import with_statement
import sys
from weboob.capabilities.recipe import ICapRecipe
from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
from weboob.core import CallErrors
__all__ = ['Cookboob']
class RecipeInfoFormatter(IFormatter):
MANDATORY_FIELDS = ('id', 'title', 'preparation_time', 'cooking_time', 'ingredients', 'instructions', 'nb_person')
MANDATORY_FIELDS = ('id', 'title', 'preparation_time', 'cooking_time', 'ingredients', 'instructions', 'nb_person', 'comments')
def format_obj(self, obj, alias):
result = u'%s%s%s\n' % (self.BOLD, obj.title, self.NC)
@ -39,12 +39,14 @@ class RecipeInfoFormatter(IFormatter):
result += 'Preparation time: %s\n' % obj.preparation_time
result += 'Cooking time: %s\n' % obj.cooking_time
result += 'Amount of people: %s\n' % obj.nb_person
result += '\n%Ingredients%s\n' % (self.BOLD, self.NC)
result += '\n%sIngredients%s\n' % (self.BOLD, self.NC)
for i in obj.ingredients:
result += ' * %s'%i
result += '\n\n%Instructions%s\n' % (self.BOLD, self.NC)
for i in obj.instructions:
result += ' * %s'%i
result += ' * %s\n'%i
result += '\n%sInstructions%s\n' % (self.BOLD, self.NC)
result += '%s\n'%obj.instructions
result += '\n%sComments%s\n' % (self.BOLD, self.NC)
for c in obj.comments:
result += ' * %s\n'%c
return result
@ -56,10 +58,10 @@ class RecipeListFormatter(PrettyFormatter):
def get_description(self, obj):
result = u''
if obj.short_description != NotAvailable:
result += 'description: %s '%obj.short_description
if obj.preparation_time != NotAvailable:
if obj.preparation_time != NotAvailable and obj.preparation_time != NotLoaded:
result += 'prep time: %smin'%obj.preparation_time
if obj.short_description != NotAvailable:
result += 'description: %s\n'%obj.short_description
return result
@ -90,7 +92,7 @@ class Cookboob(ReplApplication):
"""
recipe = self.get_object(id, 'get_recipe')
if not recipee:
if not recipe:
print >>sys.stderr, 'Recipe not found: %s' % id
return 3

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, StringField, IntField, UserError, Field
from .base import IBaseCap, CapBaseObject, StringField, IntField, Field
__all__ = ['Recipe', 'ICapRecipe']
@ -30,11 +30,14 @@ class Recipe(CapBaseObject):
"""
title = StringField('Title 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')
nb_person = IntField('The recipe was made for this amount of persons')
preparation_time = IntField('Preparation time of the recipe in minutes')
cooking_time = IntField('Cooking time of the recipe in minutes')
ingredients = Field('Ingredient list necessary for the recipe',list)
instructions = Field('Instruction step list of the recipe',list)
instructions = StringField('Instruction step list of the recipe')
comments = Field('User comments about the recipe',list)
def __init__(self, id, title):
CapBaseObject.__init__(self, id)