id with hash function

This commit is contained in:
Florent 2012-05-31 14:48:21 +02:00
commit f24a454677
2 changed files with 12 additions and 6 deletions

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import hashlib
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from .pages import AccountsList, LoginPage, LoginPage2, \
@ -99,7 +99,11 @@ class Ing(BaseBrowser):
else:
raise NotImplementedError()
while 1:
hashlist = []
for transaction in self.page.get_transactions():
while transaction.id in hashlist:
transaction.id = hashlib.md5(transaction.id + "1")
hashlist.append(transaction.id)
yield transaction
if self.page.islast():
return

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import re
import hashlib
from decimal import Decimal
from datetime import date
@ -45,19 +46,20 @@ class AccountHistory(BasePage):
def get_transactions(self):
table = self.document.findall('//tbody')[0]
i = 1
for tr in table.xpath('tr'):
id = i
op = Transaction(id)
textdate = tr.find('td[@class="op_date"]').text_content()
textraw = tr.find('td[@class="op_label"]').text_content()
# The id will be rewrite
op = Transaction(1)
amount = op.clean_amount(tr.find('td[@class="op_amount"]').text_content())
id = hashlib.md5(textdate + textraw.encode('utf-8') + amount.encode('utf-8')).hexdigest()
op.id = id
op.parse(date = date(*reversed([int(x) for x in textdate.split('/')])),
raw = textraw)
# force the use of website category
op.category = unicode(tr.find('td[@class="op_type"]').text)
op.amount = Decimal(op.clean_amount(tr.find('td[@class="op_amount"]').text_content()))
i += 1
op.amount = Decimal(amount)
yield op