Exemplo n.º 1
0
def iter_payments(account):
    # # This is probably the best example
    last_result = None

    # Loop until end of account
    while last_result == None or last_result.value != []:
        if last_result == None:
            # We will loop over the payments in baches of 20
            pagination = Pagination()
            pagination.count = 100
            params = pagination.url_params_count_only
        else:
            # When there is already a paged request, you can get the next page from it, no need to create it ourselfs:
            try:
                params = last_result.pagination.url_params_previous_page
            except BunqException:
                break

        last_result = endpoint.Payment.list(params=params,
                                            monetary_account_id=account)

        if len(last_result.value) == 0:
            # We reached the end
            break

        # The data is in the '.value' field.
        for payment in last_result.value:
            yield payment
Exemplo n.º 2
0
def iterate_transactions(account):

    # Loop until end of account
    last_result = None
    while last_result == None or last_result.value != []:
        if last_result == None:
            # Initialize pagination object
            pagination = Pagination()
            pagination.count = 100
            params = pagination.url_params_count_only
        else:
            # When there is already a paged request, you can get the next page from it, no need to create it ourselfs:
            try:
                params = last_result.pagination.url_params_previous_page
            except BunqException:
                break

        # Fetch last result
        last_result = endpoint.Payment.list(params=params,
                                            monetary_account_id=account)

        # Exit at last result
        if len(last_result.value) == 0:
            break

        # The data is in the '.value' field.
        for payment in last_result.value:
            yield payment
Exemplo n.º 3
0
    def get_all_card(self, count=_DEFAULT_COUNT):
        """
        :type count: int
        :rtype: list(endpoint.Card)
        """
        pagination = Pagination()
        pagination.count = count

        return endpoint.Card.list(pagination.url_params_count_only).value
Exemplo n.º 4
0
    def get_all_request(self, count=_DEFAULT_COUNT):
        """
        :type count: int
        :rtype: list[endpoint.RequestInquiry]
        """

        pagination = Pagination()
        pagination.count = count

        return endpoint.RequestInquiry.list(
            params=pagination.url_params_count_only).value
Exemplo n.º 5
0
    def get_all_payment(self, count=_DEFAULT_COUNT):
        """
        :type count: int
        :rtype: list[Payment]
        """

        pagination = Pagination()
        pagination.count = count

        return endpoint.Payment.list(
            params=pagination.url_params_count_only).value
Exemplo n.º 6
0
def get_all_monetary_account_active():
    pagination = Pagination()
    pagination.count = 25

    all_monetary_account_bank = endpoint.MonetaryAccountBank.list(pagination.url_params_count_only).value
    all_monetary_account_bank_active = []

    for monetary_account_bank in all_monetary_account_bank:
        if monetary_account_bank.status == "ACTIVE":
            all_monetary_account_bank_active.append(monetary_account_bank)

    return all_monetary_account_bank_active
Exemplo n.º 7
0
    def get_all_share_invite_bank_response(self, count=_DEFAULT_COUNT):
        """
        :type count: int
        :rtype: list[endpoint.ShareInviteBankResponse]
        """

        pagination = Pagination()
        pagination.count = count

        all_share_invite_bank_response = endpoint.ShareInviteBankResponse.list(
            pagination.url_params_count_only).value
        return all_share_invite_bank_response
Exemplo n.º 8
0
    def _get_all_active_monetary_accounts(self):
        pagination = Pagination()
        pagination.count = 100

        all_monetary_account_bank = endpoint.MonetaryAccountBank.list(
            pagination.url_params_count_only).value
        all_monetary_account_bank_active = []

        for monetary_account_bank in all_monetary_account_bank:
            if monetary_account_bank.status == "ACTIVE":
                account_to_append = json.loads(monetary_account_bank.to_json())
                all_monetary_account_bank_active.append(account_to_append)

        return all_monetary_account_bank_active
Exemplo n.º 9
0
    def get_all_monetary_account_active(self, count=_DEFAULT_COUNT):
        BunqContext._api_context = self._api_context
        BunqContext._user_context = self._user_context

        pagination = Pagination()
        pagination.count = count

        all_monetary_account_bank = endpoint.MonetaryAccountBank.list(
            pagination.url_params_count_only
        ).value
        all_monetary_account_bank_active = []

        for monetary_account_bank in all_monetary_account_bank:
            if monetary_account_bank.status == self._MONETARY_ACCOUNT_STATUS_ACTIVE:
                all_monetary_account_bank_active.append(monetary_account_bank)

        return all_monetary_account_bank_active
Exemplo n.º 10
0
    def get_all_monetary_account_active(self, count=_DEFAULT_COUNT):
        """
        :type count: int
        :rtype: list[endpoint.MonetaryAccountBank]
        """

        pagination = Pagination()
        pagination.count = count

        all_monetary_account_bank = endpoint.MonetaryAccountBank.list(
            pagination.url_params_count_only).value
        all_monetary_account_bank_active = []

        for monetary_account_bank in all_monetary_account_bank:
            if monetary_account_bank.status == \
                    self._MONETARY_ACCOUNT_STATUS_ACTIVE:
                all_monetary_account_bank_active.append(monetary_account_bank)

        return all_monetary_account_bank_active
Exemplo n.º 11
0
def all_transactions(dt=None):
    # This should be enough to ensure the whole account is included.
    if dt == None:
        dt = epoch

    env = ApiEnvironmentType.PRODUCTION

    if not isfile('bunq-production.conf'):
        raise Exception("No config file found, run start.py first.")

    # Reload the API context
    api_context = ApiContext.restore('bunq-production.conf')
    api_context.ensure_session_active()
    api_context.save('bunq-production.conf')

    BunqContext.load_api_context(api_context)

    # User info
    user = endpoint.User.get().value.get_referenced_object()

    # To get a list we want a pagination object.
    # When making a pagination object yourself you normally only set the 'count'
    # Then you get the url params from it using 'url_params_count_only'
    pagination = Pagination()
    pagination.count = 100

    accounts = []

    all_monetary_account_bank = endpoint.MonetaryAccountBank.list(
        pagination.url_params_count_only).value

    for monetary_account_bank in all_monetary_account_bank:
        if monetary_account_bank.status == "ACTIVE":
            accounts.append(monetary_account_bank)

    all_monetary_account_savings = endpoint.MonetaryAccountSavings.list(
        pagination.url_params_count_only).value

    for monetary_account_savings in all_monetary_account_savings:
        if monetary_account_savings.status == "ACTIVE":
            accounts.append(monetary_account_savings)

    # Reload where we where last time.
    try:
        with open("seen.pickle", "rb") as fp:
            seen = pickle.load(fp)
    except Exception:
        seen = set()
    # We will keep a list of transactions that are already processed in this set.
    # The transactions will contain:
    #  - A set of the two possible roundings of the datestamp
    #  - The ammount of money in absolute value
    #  - The description
    #  - A set containing the two accounts involved
    # The goal here is that this representation is the same for two accounts when shifting money arround.

    for a in accounts:
        aid = a.id_
        # keep track of where we are
        print(a.description)

        for p in iter_payments(aid):
            # python can handle the dates we get back
            date = dateparse.parse(p.created)

            #round to the second to get a (sort of) unique, but not to precise timestamp
            since_epoch = int(unix_time(date))

            row = [
                p.created, p.amount.value,
                p.description.replace("\r", "").replace("\n", " "),
                p.alias.label_monetary_account.iban,
                p.counterparty_alias.label_monetary_account.iban
            ]

            # frozenset can be used to hash a set, so the order does not matter.
            summary = (
                unique_float(
                    since_epoch),  #take both so there is norounding problem
                abs(float(p.amount.value)),
                p.description,
                frozenset([
                    p.alias.label_monetary_account.iban,
                    p.counterparty_alias.label_monetary_account.iban
                ]))

            # Still in range
            if date >= dt:
                if summary in seen:
                    continue
                else:
                    seen.add(summary)
                    yield (row)
            else:
                break

    with open("seen.pickle", "wb") as fp:
        pickle.dump(seen, fp)