Skip to content
module.py 3.03 KiB
Newer Older
# -*- coding: utf-8 -*-

Famil Os's avatar
Famil Os committed
# Copyright(C) 2014 Vicnet
Roger Philibert's avatar
Roger Philibert committed
# This file is part of a woob module.
Roger Philibert's avatar
Roger Philibert committed
# This woob module 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.
#
Roger Philibert's avatar
Roger Philibert committed
# This woob module 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
Roger Philibert's avatar
Roger Philibert committed
# along with this woob module. If not, see <http://www.gnu.org/licenses/>.
from woob.capabilities.pricecomparison import CapPriceComparison, Price
from woob.tools.backend import Module
Bezleputh's avatar
Bezleputh committed
from .product import LaCentraleProduct

from .browser import LaCentraleBrowser


Florent's avatar
Florent committed
__all__ = ['LaCentraleModule']
class LaCentraleModule(Module, CapPriceComparison):
    NAME = 'lacentrale'
    MAINTAINER = u'Vicnet'
Florent's avatar
Florent committed
    EMAIL = 'vo.publique@gmail.com'
Romain Bignon's avatar
Romain Bignon committed
    VERSION = '3.6'
    DESCRIPTION = 'Vehicule prices at LaCentrale.fr'
    LICENSE = 'AGPLv3+'
    BROWSER = LaCentraleBrowser

Famil Os's avatar
Famil Os committed
    def search_products(self, patternString=None):
Florent's avatar
Florent committed
        criteria = {}
Famil Os's avatar
Famil Os committed
        patterns = []
        if patternString:
            patterns = patternString.split(',')
        for pattern in patterns:
            pattern = pattern.lower()
            if u'' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['prix_maxi'] = pattern[:pattern.find(u'')].strip()
            if u'km' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['km_maxi'] = pattern[:pattern.find(u'km')].strip()
Florent's avatar
Florent committed
            if u'p' in pattern[-1]:  # last char = p
                criteria['nbdoors'] = pattern[:pattern.find(u'p')].strip()
            if u'cit' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['Citadine'] = 'citadine&SS_CATEGORIE=40'
            if u'dep' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['dptCp'] = pattern.replace('dep', '')
            if u'pro' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['witchSearch'] = 1
            if u'part' in pattern:
Bezleputh's avatar
Bezleputh committed
                criteria['witchSearch'] = 0
            if u'diesel' in pattern:
                criteria['energie'] = 2
            if u'essence' in pattern:
                criteria['energie'] = 1
            if u'electrique' in pattern:
                criteria['energie'] = 4
            if u'hybride' in pattern:
                criteria['energie'] = '8,9'
        if criteria:
            product = LaCentraleProduct()
            product._criteria = criteria
            yield product
    def iter_prices(self, products):
        product = [product for product in products if product.backend == self.name]
        if product:
            return self.browser.iter_prices(product[0])
Bezleputh's avatar
Bezleputh committed
    def get_price(self, id, price=None):
        return self.browser.get_price(id, None)
Famil Os's avatar
Famil Os committed
    def fill_price(self, price, fields):
Bezleputh's avatar
Bezleputh committed
        if fields:
            price = self.get_price(price.id, price)
        return price
Famil Os's avatar
Famil Os committed
    OBJECTS = {Price: fill_price, }