Move function from IRC into transactions
This commit is contained in:
parent
5d21953199
commit
83090ff6a5
|
@ -10,16 +10,6 @@ from json import dumps
|
||||||
from settings import settings
|
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):
|
class IRCBot(irc.IRCClient):
|
||||||
def __init__(self, log):
|
def __init__(self, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
|
@ -128,7 +118,7 @@ class IRCBot(irc.IRCClient):
|
||||||
elif not rtrn:
|
elif not rtrn:
|
||||||
return dumps({"success": False, "msg": "Reference not found"})
|
return dumps({"success": False, "msg": "Reference not found"})
|
||||||
else:
|
else:
|
||||||
return dumps(convert(rtrn))
|
return dumps(rtrn)
|
||||||
|
|
||||||
def stopcall(self, call):
|
def stopcall(self, call):
|
||||||
call.stop()
|
call.stop()
|
||||||
|
|
|
@ -8,6 +8,19 @@ from json import dumps
|
||||||
from db import r
|
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):
|
class Transactions(object):
|
||||||
"""
|
"""
|
||||||
Handler class for incoming Revolut transactions.
|
Handler class for incoming Revolut transactions.
|
||||||
|
@ -73,7 +86,7 @@ class Transactions(object):
|
||||||
tx_obj = r.hgetall(tx_iter)
|
tx_obj = r.hgetall(tx_iter)
|
||||||
if tx_obj[b"reference"] == str.encode(reference):
|
if tx_obj[b"reference"] == str.encode(reference):
|
||||||
if tx_obj[b"amount"] == str.encode(amount):
|
if tx_obj[b"amount"] == str.encode(amount):
|
||||||
return tx_obj
|
return convert(tx_obj)
|
||||||
else:
|
else:
|
||||||
return "AMOUNT_INVALID"
|
return "AMOUNT_INVALID"
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue