Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions moneydashboard/moneydashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -177,19 +192,19 @@ 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 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 (
Expand Down Expand Up @@ -281,7 +296,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:
Expand Down