Skip to content

Commit

Permalink
show all accounts in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rkw committed May 25, 2024
1 parent 6db38c2 commit 43e5d92
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.2 - 25/05/2024

- show all accounts in summary

## 0.1.1 - 25/05/2024

- bugfix
Expand Down
43 changes: 30 additions & 13 deletions monzo-status
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,34 @@ class Monzo:
if i+1 < len(sys.argv) and sys.argv[i+1].isdigit():
n = int(sys.argv[i+1])

provider = Provider.one("select * from provider where name = %s", [PROVIDER])
accounts = provider.accounts(order=Config().account_order if 'account_order' in Config().keys else None)

count = 0
for account in accounts:
self.display([account], account.keys, show_headers=(count == 0 or transactions))

if transactions:
sys.stdout.write("\n")
providers = [Provider.one("select * from provider where name = %s", [PROVIDER])] + \
Provider.find("select * from provider where name != %s order by name asc", [PROVIDER])

for provider in providers:
for account in provider.accounts(order=Config().account_order if 'account_order' in Config().keys else None):
self.get_column_widths([account], account.keys)

for provider in providers:
accounts = provider.accounts(order=Config().account_order if 'account_order' in Config().keys else None)

for account in accounts:
if account.active == 0:
continue

self.display([account], account.keys, show_headers=(count == 0 or transactions))

if transactions:
sys.stdout.write("\n")

rows = list(reversed(account.transactions(orderby='created_at', orderdir='desc', limit=n)))
rows = list(reversed(account.transactions(orderby='created_at', orderdir='desc', limit=n)))

self.display(rows, Transaction.DISPLAY_KEYS)
self.display(rows, Transaction.DISPLAY_KEYS)

sys.stdout.write("\n")
sys.stdout.write("\n")

count += 1
count += 1


def get_column_widths(self, data, columns):
Expand Down Expand Up @@ -87,7 +98,10 @@ class Monzo:

if show_headers:
for key in columns:
sys.stdout.write(self.capitalise(key).ljust(self.widths[key]+2))
if key != 'name':
sys.stdout.write(self.capitalise(key).rjust(self.widths[key]+2))
else:
sys.stdout.write(self.capitalise(key).ljust(self.widths[key]+2))
sys.stdout.write("\n")

for key in columns:
Expand All @@ -101,7 +115,10 @@ class Monzo:
obj = data[i]

for key in columns:
sys.stdout.write(str(obj[key]).ljust(self.widths[key]+2))
if key != 'name':
sys.stdout.write(str(obj[key]).rjust(self.widths[key]+2))
else:
sys.stdout.write(str(obj[key]).ljust(self.widths[key]+2))

sys.stdout.write("\n")

Expand Down
4 changes: 2 additions & 2 deletions monzo_utils/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class BaseModel:

@classmethod
def one(cls, sql, params):
def one(cls, sql, params=[]):
row = DB().one(sql, params)

if row:
Expand All @@ -21,7 +21,7 @@ def one(cls, sql, params):


@classmethod
def find(cls, sql, params):
def find(cls, sql, params=[]):
table = re.sub(r'(?<!^)(?=[A-Z])', '_', cls.__name__).lower()

data = DB().query(sql, params)
Expand Down
4 changes: 4 additions & 0 deletions monzo_utils/model/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def accounts(self, orderby='name', orderdir='asc', limit=None, order=None):
sorted_accounts.append(account)
break

for account in accounts:
if account.name not in order:
sorted_accounts.append(account)

return sorted_accounts

return accounts
1 change: 1 addition & 0 deletions schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CREATE TABLE `account` (
`sortcode` varchar(8) DEFAULT NULL,
`account_no` varchar(8) DEFAULT NULL,
`account_id` varchar(64) DEFAULT NULL,
`active` tinyint(1) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY `account_provider_id_foreign` (`provider_id`),
CONSTRAINT `account_provider_id_foreign` FOREIGN KEY (`provider_id`) REFERENCES `provider` (`id`)
Expand Down
1 change: 1 addition & 0 deletions schema_sqlite3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CREATE TABLE "account" (
"sortcode" varchar(8) DEFAULT NULL,
"account_no" varchar(8) DEFAULT NULL,
"account_id" varchar(64) DEFAULT NULL,
"active" tinyint(1) NOT NULL DEFAULT 1,
CONSTRAINT "account_provider_id_foreign" FOREIGN KEY ("provider_id") REFERENCES "provider" ("id")
);
CREATE TABLE "counterparty" (
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

setup(name='monzo-utils',
version='0.1.1',
version='0.1.2',
description='Monzo Utils',
author='Mark Wadham',
url='https://github.com/m4rkw/monzo-utils',
Expand Down

0 comments on commit 43e5d92

Please sign in to comment.