From 53ce2805ac86a90806059c54ed8a83e443fd6657 Mon Sep 17 00:00:00 2001 From: Mark Ferry Date: Sat, 18 Sep 2021 15:19:28 +0100 Subject: [PATCH 1/2] Refactor _get_transactions to _get_widget_transactions --- moneydashboard/moneydashboard.py | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/moneydashboard/moneydashboard.py b/moneydashboard/moneydashboard.py index 07fe531..6c96688 100755 --- a/moneydashboard/moneydashboard.py +++ b/moneydashboard/moneydashboard.py @@ -160,8 +160,23 @@ def _get_accounts(self): accounts[account["Id"]] = account return accounts - def _get_transactions(self, type: int): - """Retrieve transactions from MoneyDashboard account""" + def _get_transactions(self, url, headers): + try: + response = self._get_session().request("GET", url, headers=headers) + response.raise_for_status() + except HTTPError as http_err: + self.__logger.error( + "[HTTP Error]: GET failed (%s) for url: %s", http_err, url + ) + raise GetTransactionListFailedException from http_err + except Exception as err: + self.__logger.error("[Error]: GET failed (%s) for url: %s", err, url) + raise GetTransactionListFailedException from err + else: + return response.json() + + def _get_widget_transactions(self, type: int): + """Retrieve transactions from MoneyDashboard widget""" if type not in self._transactionFilterTypes: self.__logger.error("Invalid Transaction Filter.") raise InvalidTransactionListTypeFilter @@ -177,19 +192,7 @@ def _get_transactions(self, type: int): ) headers = self._get_headers() - try: - response = self._get_session().request("GET", url, headers=headers) - response.raise_for_status() - except HTTPError as http_err: - self.__logger.error( - "[HTTP Error]: Failed to get Transaction List (%s)", http_err - ) - raise GetTransactionListFailedException from http_err - except Exception as err: - self.__logger.error("[Error]: Failed to get Transaction List (%s)", err) - raise GetTransactionListFailedException from err - else: - return response.json() + return self._get_transactions(url, headers) def _money_fmt(self, balance): return ( @@ -281,7 +284,7 @@ def get_balances(self): return json.dumps(balance) def get_transactions(self, type): - transactions = self._get_transactions(type) + transactions = self._get_widget_transactions(type) transaction_list = [] for transaction in transactions: From 746c3bd7e5afcd7c12176142d5121b8b2c281e07 Mon Sep 17 00:00:00 2001 From: Mark Ferry Date: Sat, 18 Sep 2021 15:21:59 +0100 Subject: [PATCH 2/2] feat: get_raw_transactions Retrieve up to 65535 transactions from the (undocumented) transactions endpoint and return them in MoneyDashboard json format. --- moneydashboard/moneydashboard.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/moneydashboard/moneydashboard.py b/moneydashboard/moneydashboard.py index 6c96688..fc90030 100755 --- a/moneydashboard/moneydashboard.py +++ b/moneydashboard/moneydashboard.py @@ -194,6 +194,18 @@ def _get_widget_transactions(self, type: int): headers = self._get_headers() return self._get_transactions(url, headers) + def get_raw_transactions(self, count: int = 65535): + """Retrieve `count` transactions in MoneyDashboard json format""" + self.__logger.info("Getting Raw Transactions...") + self._login() + + url = ( + f"https://my.moneydashboard.com/transaction/GetTransactions?limitTo={count}" + ) + + headers = self._get_headers() + return self._get_transactions(url, headers) + def _money_fmt(self, balance): return ( format_currency(Decimal(balance), self._currency, locale="en_GB")