new cap recipe and app cookboob
This commit is contained in:
parent
b562a12cb7
commit
07a357a94f
4 changed files with 200 additions and 1 deletions
2
AUTHORS
2
AUTHORS
|
|
@ -28,7 +28,7 @@ Julien Veyssier <julien.veyssier@aiur.fr>
|
||||||
* Suboob, Cineoob, QCineoob and Booblyrics developer
|
* Suboob, Cineoob, QCineoob and Booblyrics developer
|
||||||
* CreditMutuel, Geolocip, Ipinfodb, IsoHunt, Kickass, Piratebay,
|
* CreditMutuel, Geolocip, Ipinfodb, IsoHunt, Kickass, Piratebay,
|
||||||
Attilasub, Opensubtitles, Tvsubtitle, Btmon, Imdb,
|
Attilasub, Opensubtitles, Tvsubtitle, Btmon, Imdb,
|
||||||
Seeklyrics and Parolesmusique modules maintainer.
|
Seeklyrics, Parolesmusique and Parolesmania modules maintainer.
|
||||||
|
|
||||||
Christophe Benz <christophe.benz@gmail.com>
|
Christophe Benz <christophe.benz@gmail.com>
|
||||||
* Bouygues, INA, SFR and Youtube modules maintainer.
|
* Bouygues, INA, SFR and Youtube modules maintainer.
|
||||||
|
|
|
||||||
22
weboob/applications/cookboob/__init__.py
Normal file
22
weboob/applications/cookboob/__init__.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- 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 .cookboob import Cookboob
|
||||||
|
|
||||||
|
__all__ = ['Cookboob']
|
||||||
111
weboob/applications/cookboob/cookboob.py
Normal file
111
weboob/applications/cookboob/cookboob.py
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
# -*- 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 __future__ import with_statement
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from weboob.capabilities.recipe import ICapRecipe
|
||||||
|
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')
|
||||||
|
|
||||||
|
def format_obj(self, obj, alias):
|
||||||
|
result = u'%s%s%s\n' % (self.BOLD, obj.title, self.NC)
|
||||||
|
result += 'ID: %s\n' % obj.fullid
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeListFormatter(PrettyFormatter):
|
||||||
|
MANDATORY_FIELDS = ('id', 'title', 'short_description', 'preparation_time')
|
||||||
|
|
||||||
|
def get_title(self, obj):
|
||||||
|
return obj.title
|
||||||
|
|
||||||
|
def get_description(self, obj):
|
||||||
|
result = u''
|
||||||
|
if obj.short_description != NotAvailable:
|
||||||
|
result += 'description: %s '%obj.short_description
|
||||||
|
if obj.preparation_time != NotAvailable:
|
||||||
|
result += 'prep time: %smin'%obj.preparation_time
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class Cookboob(ReplApplication):
|
||||||
|
APPNAME = 'cookboob'
|
||||||
|
VERSION = '0.f'
|
||||||
|
COPYRIGHT = 'Copyright(C) 2013 Julien Veyssier'
|
||||||
|
DESCRIPTION = "Console application allowing to search for recipes on various websites."
|
||||||
|
SHORT_DESCRIPTION = "search and consult recipes"
|
||||||
|
CAPS = ICapRecipe
|
||||||
|
EXTRA_FORMATTERS = {'recipe_list': RecipeListFormatter,
|
||||||
|
'recipe_info': RecipeInfoFormatter
|
||||||
|
}
|
||||||
|
COMMANDS_FORMATTERS = {'search': 'recipe_list',
|
||||||
|
'info': 'recipe_info'
|
||||||
|
}
|
||||||
|
|
||||||
|
def complete_info(self, text, line, *ignored):
|
||||||
|
args = line.split(' ')
|
||||||
|
if len(args) == 2:
|
||||||
|
return self._complete_object()
|
||||||
|
|
||||||
|
def do_info(self, id):
|
||||||
|
"""
|
||||||
|
info ID
|
||||||
|
|
||||||
|
Get information about a recipe.
|
||||||
|
"""
|
||||||
|
|
||||||
|
recipe = self.get_object(id, 'get_recipe')
|
||||||
|
if not recipee:
|
||||||
|
print >>sys.stderr, 'Recipe not found: %s' % id
|
||||||
|
return 3
|
||||||
|
|
||||||
|
self.start_format()
|
||||||
|
self.format(recipe)
|
||||||
|
self.flush()
|
||||||
|
|
||||||
|
def do_search(self, pattern):
|
||||||
|
"""
|
||||||
|
search [PATTERN]
|
||||||
|
|
||||||
|
Search recipes.
|
||||||
|
"""
|
||||||
|
self.change_path([u'search'])
|
||||||
|
self.start_format(pattern=pattern)
|
||||||
|
for backend, recipe in self.do('iter_recipes', pattern=pattern):
|
||||||
|
self.cached_format(recipe)
|
||||||
|
self.flush()
|
||||||
66
weboob/capabilities/recipe.py
Normal file
66
weboob/capabilities/recipe.py
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
# -*- 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 .base import IBaseCap, CapBaseObject, StringField, IntField, UserError, Field
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['Recipe', 'ICapRecipe']
|
||||||
|
|
||||||
|
|
||||||
|
class Recipe(CapBaseObject):
|
||||||
|
"""
|
||||||
|
Recipe object.
|
||||||
|
"""
|
||||||
|
title = StringField('Title of the recipe')
|
||||||
|
thumbnail_url = StringField('Direct url to recipe thumbnail')
|
||||||
|
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)
|
||||||
|
|
||||||
|
def __init__(self, id, title):
|
||||||
|
CapBaseObject.__init__(self, id)
|
||||||
|
self.title = title
|
||||||
|
|
||||||
|
|
||||||
|
class ICapRecipe(IBaseCap):
|
||||||
|
"""
|
||||||
|
Recipe providers.
|
||||||
|
"""
|
||||||
|
def iter_recipes(self, pattern):
|
||||||
|
"""
|
||||||
|
Search recipes and iterate on results.
|
||||||
|
|
||||||
|
:param pattern: pattern to search
|
||||||
|
:type pattern: str
|
||||||
|
:rtype: iter[:class:`Recipe`]
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def get_recipe(self, _id):
|
||||||
|
"""
|
||||||
|
Get a recipe object from an ID.
|
||||||
|
|
||||||
|
:param _id: ID of recipe
|
||||||
|
:type _id: str
|
||||||
|
:rtype: :class:`Recipe`
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue