From 83090ff6a5ee33d320bfabda3cff78ddc1867a68 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 27 Dec 2021 21:04:57 +0000 Subject: [PATCH] Move function from IRC into transactions --- handler/irc.py | 12 +----------- handler/transactions.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/handler/irc.py b/handler/irc.py index b815d0e..003e56d 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -10,16 +10,6 @@ from json import dumps from settings import settings -def convert(data): - if isinstance(data, bytes): - return data.decode("ascii") - if isinstance(data, dict): - return dict(map(convert, data.items())) - if isinstance(data, tuple): - return map(convert, data) - return data - - class IRCBot(irc.IRCClient): def __init__(self, log): self.log = log @@ -128,7 +118,7 @@ class IRCBot(irc.IRCClient): elif not rtrn: return dumps({"success": False, "msg": "Reference not found"}) else: - return dumps(convert(rtrn)) + return dumps(rtrn) def stopcall(self, call): call.stop() diff --git a/handler/transactions.py b/handler/transactions.py index 408064a..23cc3c9 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -8,6 +8,19 @@ from json import dumps from db import r +def convert(data): + """ + Recursively convert a dictionary. + """ + if isinstance(data, bytes): + return data.decode("ascii") + if isinstance(data, dict): + return dict(map(convert, data.items())) + if isinstance(data, tuple): + return map(convert, data) + return data + + class Transactions(object): """ Handler class for incoming Revolut transactions. @@ -73,7 +86,7 @@ class Transactions(object): tx_obj = r.hgetall(tx_iter) if tx_obj[b"reference"] == str.encode(reference): if tx_obj[b"amount"] == str.encode(amount): - return tx_obj + return convert(tx_obj) else: return "AMOUNT_INVALID" return False