From 4502b9b015f8d6d1f343f28289c5dc2c253e593e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Rubinstein?= Date: Fri, 26 Jul 2013 20:53:30 +0200 Subject: [PATCH] capabilities.bank: add Transaction.unique_id --- weboob/capabilities/bank.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py index 8659ad63..8f802c3c 100644 --- a/weboob/capabilities/bank.py +++ b/weboob/capabilities/bank.py @@ -20,6 +20,7 @@ import re from datetime import date, datetime +from binascii import crc32 from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError from .collection import ICapCollection @@ -147,6 +148,22 @@ class Transaction(CapBaseObject): return "" % (self.date, label, self.amount) + def unique_id(self, seen=None, account_id=None): + crc = crc32(str(self.date)) + crc = crc32(str(self.amount), crc) + crc = crc32(self.label.encode("utf-8"), crc) + + if account_id is not None: + crc = crc32(str(account_id), crc) + + if seen is not None: + while crc in seen: + crc = crc32("*", crc) + + seen.add(crc) + + return "%08x" % (crc & 0xffffffff) + class Investment(CapBaseObject): """