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

Romain Bignon's avatar
Romain Bignon committed
# Copyright(C) 2010-2014 Romain Bignon
Romain Bignon's avatar
Romain Bignon committed
# This file is part of weboob.
Romain Bignon's avatar
Romain Bignon committed
# 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
Romain Bignon's avatar
Romain Bignon committed
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# 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, StringField, UserError
from .date import DateField
Romain Bignon's avatar
Romain Bignon committed
from .contact import Contact
__all__ = ['OptimizationNotFound', 'Optimization', 'Event', 'CapDating']
class OptimizationNotFound(UserError):
    """
    Raised when an optimization is not found.
    """
Christophe Benz's avatar
Christophe Benz committed

Florent's avatar
Florent committed
class Optimization(BaseObject):
    """
    Optimization.

    :var CONFIG: Configuration of optim can be made by
                 :class:`weboob.tools.value.Value` objects
                 in this dict.
    """
        raise NotImplementedError()

    def stop(self):
        """
        Know if the optimization is currently running.

        :rtype: bool
        """
        raise NotImplementedError()

    def get_config(self):
        """
        Get config of this optimization.

        :rtype: dict
        """
        return None

    def set_config(self, params):
        """
        Set config of this optimization.

        :param params: parameters
        :type params: dict
        """
Christophe Benz's avatar
Christophe Benz committed

Romain Bignon's avatar
Romain Bignon committed

class Event(BaseObject):
    """
    A dating event (for example a visite, a query received, etc.)
    """
    date =      DateField('Date of event')
    contact =   Field('Contact related to this event', Contact)
    type =      StringField('Type of event')
    message =   StringField('Message of the event')
Romain Bignon's avatar
Romain Bignon committed

Florent's avatar
Florent committed
class CapDating(Capability):
Romain Bignon's avatar
Romain Bignon committed
        raise NotImplementedError()
    def add_optimization(self, name, optim):
        """
        Add an optimization.

        :param name: name of optimization
        :type name: str
        :param optim: optimization
        :type optim: :class:`Optimization`
        """
        setattr(self, 'OPTIM_%s' % name, optim)

    def iter_optimizations(self):
        """
        Iter optimizations.

        :rtype: iter[:class:`Optimization`]
        """
        for attr_name in dir(self):
            if not attr_name.startswith('OPTIM_'):
                continue
            attr = getattr(self, attr_name)
            if attr is None:
                continue

        """
        Get an optimization from a name.

        :param optim: name of optimization
        :type optim: str
        :rtype: :class:`Optimization`
        """
        if not hasattr(self, 'OPTIM_%s' % optim):
            raise OptimizationNotFound()

        return getattr(self, 'OPTIM_%s' % optim)
Romain Bignon's avatar
Romain Bignon committed

    def iter_events(self):
Romain Bignon's avatar
Romain Bignon committed
        raise NotImplementedError()
Romain Bignon's avatar
Romain Bignon committed

    def iter_new_contacts(self):
        """
        Iter new contacts.

        :rtype: iter[:class:`Contact`]
        """
        raise NotImplementedError()