Skip to content
pricecomparison.py 2.59 KiB
Newer Older
Romain Bignon's avatar
Romain Bignon committed
# -*- coding: utf-8 -*-

# Copyright(C) 2012 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
Romain Bignon's avatar
Romain Bignon committed
# 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 Lesser General Public License for more details.
Romain Bignon's avatar
Romain Bignon committed
#
# You should have received a copy of the GNU Lesser General Public License
Romain Bignon's avatar
Romain Bignon committed
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


Florent's avatar
Florent committed
from .base import Capability, BaseObject, Field, DecimalField, \
                  StringField, UserError
from .date import DateField
__all__ = ['Shop', 'Price', 'Product', 'CapPriceComparison']
class PriceNotFound(UserError):
    """
    Raised when a price is not found
    """

    def __init__(self, msg='Price not found'):
        super(PriceNotFound, self).__init__(msg)
class Product(BaseObject):
Romain Bignon's avatar
Romain Bignon committed
    """
    A product.
    """
    name =      StringField('Name of product')

class Shop(BaseObject):
Romain Bignon's avatar
Romain Bignon committed
    """
    A shop where the price is.
    """
    name =      StringField('Name of shop')
    location =  StringField('Location of the shop')
    info =      StringField('Information about the shop')

class Price(BaseObject):
Romain Bignon's avatar
Romain Bignon committed
    """
    Price.
    """
    date =      DateField('Date when this price has been published')
    cost =      DecimalField('Cost of the product in this shop')
Romain Bignon's avatar
Romain Bignon committed
    currency =  StringField('Currency of the price')
    message =   StringField('Message related to this price')
    shop =      Field('Shop information', Shop)
    product =   Field('Product', Product)

Florent's avatar
Florent committed
class CapPriceComparison(Capability):
Romain Bignon's avatar
Romain Bignon committed
    """
    Capability for price comparison websites.
    """

    def search_products(self, pattern=None):
        """
        Search products from a pattern.

        :param pattern: pattern to search
        :type pattern: str
        :rtype: iter[:class:`Product`]
        """
        raise NotImplementedError()

    def iter_prices(self, products):
Romain Bignon's avatar
Romain Bignon committed
        """
        Iter prices for a product.

        :param product: product to search
        :type product: :class:`Product`
        :rtype: iter[:class:`Price`]
        """
        raise NotImplementedError()

    def get_price(self, id):
        """
        Get a price from an ID

        :param id: ID of price
        :type id: str
        :rtype: :class:`Price`
        """
        raise NotImplementedError()