Пример #1
0
def get_yesterdays_transactions(access_token, start_date, end_date):

    account_ids = [account['account_id'] for account in client.accounts_get(
        AccountsGetRequest(access_token=access_token))['accounts']
        if account['subtype'] not in OMIT_ACCOUNT_SUBTYPES]

    num_available_transactions = client.transactions_get(TransactionsGetRequest(access_token, start_date, end_date,
                                                                                options=TransactionsGetRequestOptions(
                                                                                    account_ids=account_ids)
                                                                                ))['total_transactions']
    num_pages = math.ceil(num_available_transactions /
                          MAX_TRANSACTIONS_PER_PAGE)
    transactions = []

    for page_num in range(num_pages):
        transactions += [transaction
                         for transaction in client.transactions_get(TransactionsGetRequest(access_token, start_date, end_date,
                                                                                           options=TransactionsGetRequestOptions(
                                                                                               account_ids=account_ids, offset=page_num * MAX_TRANSACTIONS_PER_PAGE,
                                                                                               count=MAX_TRANSACTIONS_PER_PAGE)

                                                                                           ))['transactions']
                         if transaction['category'] is None
                         or not any(category in OMIT_CATEGORIES
                                    for category in transaction['category'])]

    return transactions
Пример #2
0
    def read_records(
        self,
        sync_mode: SyncMode,
        cursor_field: List[str] = None,
        stream_slice: Mapping[str, Any] = None,
        stream_state: Mapping[str, Any] = None,
    ) -> Iterable[Mapping[str, Any]]:
        stream_state = stream_state or {}
        date = stream_state.get("date")
        if not date:
            date = datetime.date.fromtimestamp(0)
        else:
            date = datetime.date.fromisoformat(date)
        if date >= datetime.datetime.utcnow().date():
            return

        transaction_response = self.client.transactions_get(
            TransactionsGetRequest(access_token=self.access_token,
                                   start_date=date,
                                   end_date=datetime.datetime.utcnow().date()))

        yield from map(
            lambda x: x.to_dict(),
            sorted(transaction_response["transactions"],
                   key=lambda t: t["date"]))
Пример #3
0
    def _get_transactions_response(self, start_date, end_date=datetime.datetime.utcnow().date(), offset=0):
        options = TransactionsGetRequestOptions()
        options.offset = offset

        return self.client.transactions_get(
            TransactionsGetRequest(access_token=self.access_token, start_date=start_date, end_date=end_date, options=options)
        )
Пример #4
0
def all_transactions(access_token, start_date, end_date):
    options = TransactionsGetRequestOptions()
    request = TransactionsGetRequest(
        access_token=access_token,
        start_date=start_date.date(),
        end_date=end_date.date(),
        options=options
    )
    response = client.transactions_get(request)
    transactions = response.transactions
    return transactions
Пример #5
0
def get_transactions():
    # Pull transactions for the last 30 days
    start_date = (datetime.datetime.now() - timedelta(days=30))
    end_date = datetime.datetime.now()
    try:
        options = TransactionsGetRequestOptions()
        request = TransactionsGetRequest(access_token=access_token,
                                         start_date=start_date.date(),
                                         end_date=end_date.date(),
                                         options=options)
        response = client.transactions_get(request)
        pretty_print_response(response.to_dict())
        return jsonify(response.to_dict())
    except plaid.ApiException as e:
        error_response = format_error(e)
        return jsonify(error_response)