From 3e1b2813c22ede6d87030a71624a27190beb8960 Mon Sep 17 00:00:00 2001 From: Mark Wadham Date: Sat, 13 Jul 2024 20:22:02 +0100 Subject: [PATCH] update --- monzo-search | 25 +++++++++++++++++++++---- monzo_utils/lib/db_driver/dynamodb.py | 2 +- monzo_utils/lib/monzo_sync.py | 3 ++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/monzo-search b/monzo-search index a9b07fe..b5551db 100755 --- a/monzo-search +++ b/monzo-search @@ -200,8 +200,8 @@ class Monzo: filter_expression = 'contains(#description, :description)' - attr_names['#description'] = 'description' - attr_values[':description'] = {'S': query_string} + attr_names['#description'] = 'description_search' + attr_values[':description'] = {'S': query_string.lower()} if query_string.replace('.','').isdigit(): # integer value is queried as a range .00 - .99 @@ -224,7 +224,7 @@ class Monzo: attr_values[':zero'] = {'N': '0'} attr_values[':money_value'] = {'N': query_string} - transactions = Transaction.search(filter_expression=filter_expression, attr_names=attr_names, attr_values=attr_values) + transactions = self.sort_transactions(Transaction.search(filter_expression=filter_expression, attr_names=attr_names, attr_values=attr_values)) # transactions = query.groupBy('`transaction`.id') \ # .orderBy('date, created_at', 'asc') \ @@ -232,7 +232,7 @@ class Monzo: # # transactions = self.process_pending_refunds(transactions) - display_columns = ['id','account','pot','date','money_in','money_out','description'] + display_columns = ['account','pot','date','money_in','money_out','description'] if show_declined: display_columns.append('decline_reason') @@ -398,4 +398,21 @@ class Monzo: return dt + def sort_transactions(self, transactions): + sorted_transactions = [] + transactions_by_timestamp = {} + + for transaction in transactions: + if transaction.timestamp not in transactions_by_timestamp: + transactions_by_timestamp[transaction.timestamp] = [] + + transactions_by_timestamp[transaction.timestamp].append(transaction) + + for timestamp in sorted(transactions_by_timestamp): + for transaction in transactions_by_timestamp[timestamp]: + sorted_transactions.append(transaction) + + return sorted_transactions + + Monzo(sys.argv) diff --git a/monzo_utils/lib/db_driver/dynamodb.py b/monzo_utils/lib/db_driver/dynamodb.py index 506b0f8..7540ec5 100644 --- a/monzo_utils/lib/db_driver/dynamodb.py +++ b/monzo_utils/lib/db_driver/dynamodb.py @@ -312,7 +312,7 @@ def get_columns(self, table, exclude=None): def put_item(self, table, data): - self.dbd.put_item( + resp = self.dbd.put_item( TableName=f"{self.prefix}_{table}", Item=self.to_dbd(data) ) diff --git a/monzo_utils/lib/monzo_sync.py b/monzo_utils/lib/monzo_sync.py index 64c77d3..4f9bbee 100755 --- a/monzo_utils/lib/monzo_sync.py +++ b/monzo_utils/lib/monzo_sync.py @@ -403,7 +403,8 @@ def add_transaction(self, account, mo_transaction, pot_account_ids, pot_id=None) if type(mo_transaction.metadata) == dict: for key in mo_transaction.metadata: - transaction_data[key] = mo_transaction.metadata[key] + if key.split('_')[0] != 'metadata': + transaction_data['metadata_' + key] = mo_transaction.metadata[key] transaction.update(transaction_data)