benevity transfer support

This commit is contained in:
Kasownik 2020-03-03 18:59:35 +01:00
parent 611a71986a
commit bbdcd27c6d

View file

@ -94,10 +94,15 @@ class IBRow(RawTransfer):
OWN_ACCOUNTS = config["OWN_ACCOUNTS"]
def __unicode__(self):
return u"{} *{} #{} @{} -\"{}\" -#{} => +\"{}\" +#{} [{}.{:02d} {}] ({}.{:02d} {}) ~\"{}\"".format(
if self.balance is not None:
return u"{} *{} #{} @{} -\"{}\" -#{} => +\"{}\" +#{} [{}.{:02d} {}] ({}.{:02d} {}) ~\"{}\"".format(
self.type, self.index, self.on_account, self.date, self.from_name, self.from_account,
self.to_name, self.to_account, self.amount/100, self.amount%100,
self.currency, self.balance/100, self.balance%100, self.balance_currency, self.title)
return u"{} *{} #{} @{} -\"{}\" -#{} => +\"{}\" +#{} [{}.{:02d} {}] (?) ~\"{}\"".format(
self.type, self.index, self.on_account, self.date, self.from_name, self.from_account,
self.to_name, self.to_account, self.amount/100, self.amount%100,
self.currency, self.balance/100, self.balance%100, self.balance_currency, self.title)
self.currency, self.title)
def __str__(self):
return unicode(self).encode("utf-8")
def __repr__(self):
@ -110,7 +115,7 @@ class IBRow(RawTransfer):
self.uid = row['id']
self.title = row['title']
self.amount = round(row['amount'] * 100)
self.amount = int(round(row['amount'] * 100))
self.currency = row['currency']
self.on_account = own_account
@ -175,6 +180,7 @@ class IBParser(object):
"((?:[A-Za-z]{2})?[0-9]{2})[ ]?([A-Z]{4})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{2})", # 22 characters including BIC bank code - Ireland
"((?:[A-Za-z]{2})?[0-9]{2})[ ]?([A-Z]{4})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{2})", # 18 characters including BIC bank code - Netherlands
"((?:[A-Za-z]{2})?[0-9]{2})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{4})[ ]?([0-9]{2})", # 22 digits - Germany
"^([0-9]{5})$", # 5 digits - weird special hax for Benevity (UK?)
]
for f in formats:
m = re.search(f, s)
@ -394,7 +400,10 @@ if __name__ == "__main__":
continue
with open(CACHE_DIR + "/" + f, 'r') as fd:
history_logs[account_number] = json.loads(fd.read())
try:
history_logs[account_number] = json.loads(fd.read())
except Exception as e:
logging.error("Failed to decode {}: {}".format(f, e))
logging.debug("Loading \"{}\" as \"{}\"".format(f, account_number))
else:
@ -445,6 +454,8 @@ if __name__ == "__main__":
stats[account_number]["skipped"] = 0
for row in parser.get():
if not session.query(IBRow).filter_by(uid=row.uid).first():
if args.no_action:
print(row)
session.add(row)
stats[account_number]["added"] += 1
else: