Example #1
0
 def update_module_list(self):
     w = Weboob()
     logger.info('Weboob: calling update_repositories')
     w.repositories.update_repositories()
     weboob_modules = w.repositories.get_all_modules_info('CapDocument')
     module_name2obj = {}
     for module in self.search_read([], ['name']):
         module_name2obj[module['name']] = self.browse(module['id'])
     for name, info in weboob_modules.iteritems():
         vals = {
             'name': name,
             'maintainer': info.maintainer,
             'license': info.license,
             'description': info.description,
             'available_version': info.version,
             'state': 'uninstalled',
         }
         if info.is_installed():
             vals.update({
                 'has_parameters': self.has_parameter(w, name),
                 'state': 'installed',
                 'installed_version': info.version,
             })
         if name in module_name2obj:
             module_name2obj[name].write(vals)
         else:
             self.create(vals)
Example #2
0
def main(filename):
    weboob = Weboob()
    try:
        hds = weboob.build_backend('hds')
    except ModuleLoadError, e:
        print >>sys.stderr, 'Unable to load "hds" module: %s' % e
        return 1
Example #3
0
def retrieve_accounts(bank_name):
    w = Weboob()
    w.load_backends(caps=(CapBank, ))
    bank_backend = w.get_backend(bank_name)
    if bank_backend:
        bank = Bank.get_or_create(name=bank_name)
        accounts = bank_backend.iter_accounts()
        for account in accounts:
            logger.info(
                f'[Accounts] Retrieving account {account.label} - {account.balance} from {bank_name}'
            )

            db_account = Account.get_or_none(bank=bank[0],
                                             account_id=account.id)
            if db_account is None:
                db_account = Account.create(bank=bank[0],
                                            account_id=account.id,
                                            user=1,
                                            label=account.label,
                                            balance=account.balance)
            else:
                db_account.label = account.label
                db_account.balance = account.balance
                db_account.save()
            transactions = bank_backend.iter_history(account)
            for transaction in transactions:
                db_transanction = Transaction.get_or_create(
                    account=db_account.id,
                    label=transaction.label,
                    category=transaction.category,
                    amount=transaction.amount,
                    date=transaction.date)
Example #4
0
    def get_app_dictionary(self):
        if self.enabled:
            # we wan't to update every VALUES_UPDATE_INTERVAL minutes
            if self.status is None or timezone.now(
            ) >= self.last_activity + timedelta(
                    minutes=settings.VALUES_UPDATE_INTERVAL):
                # Weboob 1.2 example http://dev.weboob.org/
                weboob = Weboob()
                weboob.load_backends(CapParcel)
                for backend in list(weboob.iter_backends()):
                    if backend.name == self.parcel_carrier:
                        parcel = backend.get_parcel_tracking(self.parcel)
                        parcel_dict = parcel.to_dict()
                        self.status = parcel_dict['status']
                        if parcel_dict['arrival'] == 'Not loaded':
                            self.arrival = None
                        else:
                            pass
                            #parcel_dict['arrival']
                        self.url = parcel_dict['url']
                        self.info = parcel_dict['info']
                        self.save()

        return {
            'parcel': self.parcel,
            'parcel_carrier': self.parcel_carrier,
            'arrival': self.arrival,
            'status': self.status,
            'info': self.info
        }
Example #5
0
    def __init__(self):
        self.ind = appindicator.Indicator.new(APPINDICATOR_ID,
                                              os.path.abspath(resource_filename('boobank_indicator.data',
                                                                                'indicator-boobank.png')),
                                              appindicator.IndicatorCategory.APPLICATION_STATUS)

        self.menu = Gtk.Menu()
        self.ind.set_menu(self.menu)

        logging.basicConfig()
        if 'weboob_path' in os.environ:
            self.weboob = Weboob(os.environ['weboob_path'])
        else:
            self.weboob = Weboob()

        self.weboob.load_backends(CapBank)
Example #6
0
    def update(self):
        """
        Update Weboob modules.
        """
        # Weboob has an offending print statement when it "Rebuilds index",
        # which happen at every run if the user has a local repository. We need
        # to silence it, hence the temporary redirect of stdout.
        sys.stdout = open(os.devnull, "w")
        try:
            self.weboob.update(progress=DummyProgress())
        except ConnectionError as exc:
            # Do not delete the repository if there is a connection error.
            raise exc
        except Exception:
            # Try to remove the data directory, to see if it changes a thing.
            # This is especially useful when a new version of Weboob is
            # published and/or the keyring changes.
            shutil.rmtree(self.weboob_data_path)
            os.makedirs(self.weboob_data_path)

            # Recreate the Weboob object as the directories are created
            # on creating the Weboob object.
            self.weboob = Weboob(workdir=self.weboob_data_path,
                                 datadir=self.weboob_data_path)

            # Rewrite sources.list file
            self.write_weboob_sources_list()

            # Retry update
            self.weboob.update(progress=DummyProgress())
        finally:
            # Restore stdout
            sys.stdout = sys.__stdout__
Example #7
0
 def __init__(self):
     logger.debug("class init")
     self.peg_perco_names = []
     self.weboob = Weboob()
     self.weboob.load_backends(CapBank)
     logger.debug('backends loaded: %s' % list(self.weboob.iter_backends()))
     self.investments = {}
Example #8
0
 def __init__(self, backend_name, download_directory, links_directory):
     self.download_directory = download_directory
     self.links_directory = links_directory
     self.backend_name = backend_name
     self.backend = None
     self.weboob = Weboob()
     self.weboob.load_backends(modules=[self.backend_name])
     self.backend=self.weboob.get_backend(self.backend_name)
    def weboob_download(self, credentials, logs):
        logger.info(
            'Start weboob operations with module %s',
            self.weboob_module_id.name)
        w = Weboob()
        back = w.build_backend(
            self.weboob_module_id.name, params=credentials, name='odoo')

        try:
            sub = back.iter_subscription().next()
        except BrowserIncorrectPassword:
            logs['msg'].append(_('Wrong password.'))
            logs['result'] = 'failure'
            return []

        bills = back.iter_bills(sub)
        start_date = self.download_start_date
        invoices = []
        for bill in bills:
            logger.debug('bill.id=%s, bill.fullid=%s', bill.id, bill.fullid)
            inv_details = bill.to_dict()
            logger.info('bill.to_dict=%s', inv_details)
            # bill.to_dict=OrderedDict([
            # ('id', u'60006530609_216421161'),
            # ('url', u'https://api.bouyguestelecom.fr/comptes-facturat...'),
            # ('date', date(2018, 7, 16)),
            # ('format', u'pdf'),
            # ('label', u'Juillet 2018'),
            # ('type', u'bill'),
            # ('transactions', []),
            # ('price', Decimal('30.99')),
            # ('currency', u'EUR'),
            # ('vat', NotLoaded),
            # ('duedate', NotLoaded), ('startdate', NotLoaded),
            # ('finishdate', NotLoaded), ('income', False)])
            # Do we have invoice number here ? NO
            logger.info("Found invoice dated %s", inv_details.get('date'))
            if (
                    start_date and
                    inv_details.get('date') and
                    fields.Date.to_string(inv_details['date']) < start_date):
                logger.info(
                    'Skipping invoice %s dated %s dated before '
                    'download_start_date %s',
                    inv_details.get('label'), inv_details['date'], start_date)
                continue

            logger.info('Start to download bill with full ID %s', bill.fullid)
            pdf_inv = back.download_document(bill.id)
            filename = 'invoice_%s_%s.%s' % (
                self.weboob_module_id.name,
                inv_details.get('label') and
                inv_details['label'].replace(' ', '_'),
                inv_details.get('format', 'pdf'))
            invoices.append((pdf_inv.encode('base64'), filename))
        return invoices
 def __init__(self, name, backend_name, my_download_directory,
              my_links_directory):
     self.download_directory = my_download_directory
     self.links_directory = my_links_directory
     self.backend_name = backend_name
     self.backend = None
     self.weboob = Weboob()
     self.weboob.load_backends(modules=self.backend_name, )
     self.backend = self.weboob.get_backend(self.backend_name)
     self.name = name
Example #11
0
    def banks_supported():
        """
        Return all the banks supported by weboob.
        :return: [(module_name, Module_description)]
        """
        banks_supported = []
        weboob = Weboob()
        modules = weboob.repositories.get_all_modules_info(CapBank)
        for bank_module_name, info in modules.items():
            banks_supported.append((bank_module_name, info.description))

        return banks_supported
Example #12
0
def get_backends():
    w = Weboob()

    result = {}
    for instance_name, name, params in sorted(
            w.backends_config.iter_backends()):
        module = w.modules_loader.get_or_load_module(name)
        if not module.has_caps(CapBank):
            continue

        result[instance_name] = {'module': name}

    return result
Example #13
0
 def install(self):
     w = Weboob()
     for module in self:
         if module.state == 'uninstalled':
             logger.info('Starting to install weboob module %s',
                         module.name)
             w.repositories.install(module.name)
             has_parameter = self.has_parameter(w, module.name)
             module.write({
                 'state': 'installed',
                 'installed_version': module.available_version,
                 'has_parameter': has_parameter,
             })
             logger.info('Weboob module %s is now installed', module.name)
Example #14
0
    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)

        self.backends = {}
        self.backend_instance = None
        self.backend = None
        self.weboob = Weboob()

        if self.weboob.load_backends(modules=[self.BACKEND]):
            # provide the tests with all available backends
            self.backends = self.weboob.backend_instances
            # chose one backend (enough for most tests)
            self.backend_instance = choice(self.backends.keys())
            self.backend = self.backends[self.backend_instance]
Example #15
0
    def __init__(self, *args, **kwargs):
        super(BackendTest, self).__init__(*args, **kwargs)

        self.backends = {}
        self.backend_instance = None
        self.backend = None
        self.weboob = Weboob()

        # Skip tests when passwords are missing
        self.weboob.requests.register('login', self.login_cb)

        if self.weboob.load_backends(modules=[self.MODULE]):
            # provide the tests with all available backends
            self.backends = self.weboob.backend_instances
Example #16
0
def get_accounts(bname):
    w = Weboob()

    w.load_backends(names=[bname])
    backend = w.get_backend(bname)

    results = {}
    for account in backend.iter_accounts():
        # a unicode bigger than 8 characters used as key of the table make some bugs in the C++ code
        # convert to string before to use it
        results[str(account.id)] = {
            'name': account.label,
            'balance': int(account.balance * 100),
            'type': int(account.type),
        }
    return results
Example #17
0
def get_transactions(bname, accid, maximum):
    w = Weboob()

    w.load_backends(names=[bname])
    backend = w.get_backend(bname)

    acc = backend.get_account(accid)
    results = {}
    results['id'] = acc.id
    results['name'] = acc.label
    results['balance'] = int(acc.balance * 100)
    results['type'] = int(acc.type)
    results['transactions'] = []

    try:
        count = int(maximum)
        if count < 1:
            count = 0
    except:
        count = 0
    i = 0
    first = True
    rewriteid = False
    seen = set()
    for tr in backend.iter_history(acc):
        if first:
            if tr.id == u'0' or tr.id == u'':
                rewriteid = True
            first = False
        if rewriteid:
            tr.id = tr.unique_id(seen)
        t = {
            'id': tr.id,
            'date': tr.date.strftime('%Y-%m-%d'),
            'rdate': tr.rdate.strftime('%Y-%m-%d'),
            'type': int(tr.type),
            'raw': tr.raw,
            'category': tr.category,
            'label': tr.label,
            'amount': int(tr.amount * 100),
        }
        results['transactions'].append(t)
        i += 1
        if count != 0 and i >= count:
            break

    return results
Example #18
0
    def update(self):
        """
        Update Weboob modules.
        """
        self.copy_fakemodules()

        # Weboob has an offending print statement when it "Rebuilds index",
        # which happen at every run if the user has a local repository. We need
        # to silence it, hence the temporary redirect of stdout.
        sys.stdout = open(os.devnull, "w")

        # Create the backup before doing anything.
        self.backup_data_dir()

        try:
            self.weboob.update(progress=DummyProgress())
        except (ConnectionError, HTTPError) as exc:
            # Do not delete the repository if there is a connection error or the repo has problems.
            raise exc
        except Exception:
            # Try to remove the data directory, to see if it changes a thing.
            # This is especially useful when a new version of Weboob is
            # published and/or the keyring changes.
            shutil.rmtree(self.weboob_data_path)
            os.makedirs(self.weboob_data_path)

            # Recreate the Weboob object as the directories are created
            # on creating the Weboob object.
            self.weboob = Weboob(workdir=self.weboob_data_path,
                                 datadir=self.weboob_data_path)

            # Rewrite sources.list file
            self.write_weboob_sources_list()

            # Retry update
            try:
                self.weboob.update(progress=DummyProgress())
            except Exception as exc:
                # If it still fails, just restore the previous state.
                self.restore_data_dir()
                # Re-throw the exception so that the user is warned of the problem.
                raise exc
        finally:
            # Restore stdout
            sys.stdout = sys.__stdout__
            # Clean the backup.
            self.clean_data_dir_backup()
Example #19
0
def new_jobs():
    w = Weboob()
    w.load_backends(CapJob)
    #w['popolemploi']
    words = u'python'
    jobs = w.search_job(words)
    jobs = list(jobs)
    Poleemploi.query.delete()
    for job in jobs:
        new = Poleemploi(society_name=job.society_name,
                         place=job.place,
                         title=job.title,
                         contract_type=job.contract_type,
                         publication_date=job.publication_date)
        db.session.add(new)
        db.session.commit()
    return redirect(url_for('jobs_index'))
Example #20
0
    def _get_all_transactions(self):

        weboob = Weboob()
        backend = weboob.load_backends(
            names=['bp'])['bp']  # TODO Make it generic

        account_transactions = []
        for account in backend.iter_accounts():
            if account.label != 'COMPTE BANCAIRE':  # TODO Make it generic
                continue
            for weboob_transaction in backend.iter_history(account):
                transaction = Transaction(date=weboob_transaction.date,
                                          amount=float(
                                              weboob_transaction.amount),
                                          label=weboob_transaction.label)
                account_transactions.append(transaction)
        return account_transactions
Example #21
0
    def __init__(self, weboob_data_path, fakemodules_path,
                 sources_list_content, is_prod):
        """
        Create a Weboob instance.

        :param weboob_data_path: Weboob path to use.
        :param fakemodules_path: Path to the fake modules directory in user
        data.
        :param sources_list_content: Optional content of the sources.list file,
        as an array of lines, or None if not present.
        :param is_prod: whether we're running in production or not.
        """
        # By default, consider we don't need to update the repositories.
        self.needs_update = False

        self.fakemodules_path = fakemodules_path
        self.sources_list_content = sources_list_content

        if not os.path.isdir(weboob_data_path):
            os.makedirs(weboob_data_path)

        # Set weboob data directory and sources.list file.
        self.weboob_data_path = weboob_data_path
        self.weboob_backup_path = os.path.normpath('%s.bak' % weboob_data_path)
        self.write_weboob_sources_list()

        # Create a Weboob object.
        self.weboob = Weboob(workdir=weboob_data_path,
                             datadir=weboob_data_path)
        self.backend = None
        self.storage = None

        # To make development more pleasant, always copy the fake modules in
        # non-production modes.
        if not is_prod:
            self.copy_fakemodules()

        # To make development more pleasant, always copy the fake modules in
        # non-production modes.
        if not is_prod:
            self.copy_fakemodules()

        # Update the weboob repos only if new repos are included.
        if self.needs_update:
            self.update()
 def weboob_module_id_change(self):
     if self.weboob_module_id and self.weboob_module_id.has_parameters:
         w = Weboob()
         bmod = w.modules_loader.get_or_load_module(
             self.weboob_module_id.name)
         new_params = self.env['weboob.parameter']
         for key, value in bmod.config.iteritems():
             if key not in ['login', 'password']:
                 note = value.label or ''
                 if value.choices:
                     options = ', '.join([
                         "'%s' (%s)" % (key_opt, help_opt)
                         for (key_opt, help_opt) in value.choices.items()])
                     note = _("%s. Possible values: %s.") % (note, options)
                 param = new_params.new({
                     'key': key,
                     'note': note,
                     })
                 new_params += param
         self.weboob_parameter_ids = new_params
Example #23
0
def bank_connection_and_load_transactions(request, pk):
    bank = get_object_or_404(Banks, pk=pk)
    w = Weboob()

    # TODO: Vérifier que les champs ne sont pas vide avant de lancer la connexion
    # TODO: si erreur de connexion, alors raise une erreur et revenir vers une autre page ?
    # TODO: affecter un owner_of_account lorsqu'un account est créé

    if request.method == 'POST':
        form = BankConnectionForm(instance=bank, data=request.POST)

        if form.is_valid():
            # TODO: vérifier que le mot de passe est identique à celui stocké en base if any (sous forme cryptée)
            logger.warning(
                '============= bank_connection_and_load_transactions __ bank.module_weboob.name_of_module = :: %s',
                bank.module_weboob.name_of_module)
            wb = w.load_backend(
                bank.module_weboob.name_of_module, bank.name_of_bank, {
                    'login': form.cleaned_data['bank_login'],
                    'password': form.cleaned_data['bank_password']
                })

            # Get list of available account(s) in the bank
            list_of_accounts = list(wb.iter_accounts())

            # Get list of transactions coming from bank history
            context = load_transactions(request, wb, bank, list_of_accounts)
            return render(request,
                          'ManageGesfi/load_transactions_from_account.html',
                          context)

    else:
        form = BankConnectionForm(instance=bank)

    context = {
        'bank': bank,
        'form': form,
    }
    return render(
        request, 'banksandaccounts/bank_connection_and_load_transactions.html',
        context)
Example #24
0
def load_list_of_modules_in_database(request):
    '''
    function to load list of weboob modules in database
    :param request:
    :return:
    '''
    w = Weboob()
    w.update()

    listbanks = w.repositories.get_all_modules_info(CapBank)

    db_wm_list = WeboobModules.objects.all()

    list_of_db_modules = []
    for key in db_wm_list:
        list_of_db_modules.append(key.name_of_module)

    list_of_banks = []
    for key, val in listbanks.items():
        wm = WeboobModules()
        data_bank = {}

        data_bank['module'] = key
        wm.name_of_module = key

        data_bank['description'] = val.description
        wm.description_of_module = val.description

        list_of_banks.append(data_bank)
        if wm.name_of_module not in list_of_db_modules:
            wm.save()

    list_of_banks.sort(key=lambda k: k['module'])

    db_wm_list = WeboobModules.objects.all()


    # context = {'list_of_banks': list_of_banks}
    context = {'list_of_banks': db_wm_list, 'load': True}

    return render(request, 'ManageWeboob/list_of_available_modules.html', context)
Example #25
0
 def upgrade(self):
     w = Weboob()
     logger.info('Weboob: calling update_repositories')
     w.repositories.update_repositories()
     for module in self:
         if module.state == 'installed':
             # it seems that you must call install to update a module!
             logger.info('Starting to upgrade module %s', module.name)
             try:
                 w.repositories.install(module.name)
             except ModuleInstallError as e:
                 raise UserError(
                     _("Error when upgrading module '%s'. Error message: %s."
                       ) % (module.name, e))
             new_version = module.get_installed_version(w)
             logger.info(
                 'Weboob module %s has been updated from version %s to %s',
                 module.name, module.installed_version, new_version)
             module.write({
                 'installed_version': new_version,
                 'available_version': new_version,
             })
Example #26
0
def bank_create_with_weboob_module(request, pk):

    w = Weboob()

    if request.method == 'POST':
        form = BankForm(data=request.POST)
        if form.is_valid():
            bank = form.save(commit=False)
            bank.bank_password = make_password(
                form.cleaned_data['bank_password'])
            bank.save()

            w.load_backend(
                bank.module_weboob.name_of_module, bank.name_of_bank, {
                    'login': form.cleaned_data['bank_login'],
                    'password': form.cleaned_data['bank_password']
                })

            # Get list of available account(s) in the bank
            list_of_accounts = list(w.iter_accounts())

            # Get list of transactions coming from bank history
            context = load_transactions(request, w, bank, list_of_accounts)
            return render(request,
                          'ManageGesfi/load_transactions_from_account.html',
                          context)

    else:
        form = BankForm()

    context = {
        'form': form,
        'create': True
        # TODO: ajouter un flag "create with weboob" pour rediriger vers load_transactions (et créer les comptes)
    }
    return render(request, 'banksandaccounts/bank_edit.html', context)
Example #27
0
    def __init__(self, weboob_data_path):
        """
        Create a Weboob instance.

        :param weboob_data_path: Weboob path to use.
        """
        # By default, consider we don't need to update the repositories.
        self.needs_update = False

        if not os.path.isdir(weboob_data_path):
            os.makedirs(weboob_data_path)

        # Set weboob data directory and sources.list file.
        self.weboob_data_path = weboob_data_path
        self.write_weboob_sources_list()

        # Create a Weboob object.
        self.weboob = Weboob(workdir=weboob_data_path,
                             datadir=weboob_data_path)
        self.backends = collections.defaultdict(dict)

        # Update the weboob repos only if new repos are included.
        if self.needs_update:
            self.update()
Example #28
0
 def __init__(self, bot):
     Thread.__init__(self)
     self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE))
     self.weboob.load_backends()
     self.bot = bot
     self.bot.weboob = self.weboob
Example #29
0
 def create_weboob(self):
     return Weboob(scheduler=MonboobScheduler(self))
Example #30
0
 def create_weboob(self):
     return Weboob()