LCL: fix history command due to website changes

Signed-off-by: Pierre Mazière <pierre.maziere@gmail.com>
Signed-off-by: Romain Bignon <romain@peerfuse.org>
This commit is contained in:
Pierre Mazière 2011-04-21 14:14:54 +02:00 committed by Romain Bignon
commit c7968faa20

View file

@ -73,33 +73,28 @@ class AccountsPage(BasePage):
class AccountHistoryPage(BasePage): class AccountHistoryPage(BasePage):
def on_loaded(self): def on_loaded(self):
self.operations = [] self.operations = []
done=False for td in self.document.iter('td'):
for table in self.document.getiterator('table'): text=td.findtext("b")
title_tr=table.find('tr') if text is None:
if title_tr is None:
continue continue
for text in title_tr.itertext(): prefix='Opérations effectuées'
prefix='Opérations effectuées' if text.startswith(prefix.decode('utf-8')):
if text.startswith(prefix.decode('utf-8')): table=td.getparent().getparent()
for tr in table.iter('tr'): for tr in table.iter('tr'):
tr_class=tr.attrib.get('class') tr_class=tr.attrib.get('class')
if tr_class == 'tbl1' or tr_class=='tbl2': if tr_class == 'tbl1' or tr_class=='tbl2':
tds=tr.findall('td') tds=tr.findall('td')
d=date(*reversed([int(x) for x in tds[0].text.split('/')])) d=date(*reversed([int(x) for x in tds[0].text.split('/')]))
label=u''+tds[1].find('a').text.strip() label=u''+tds[1].find('a').text.strip()
if tds[3].text.strip() != u"": if tds[3].text.strip() != u"":
amount = - float(tds[3].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ','')) amount = - float(tds[3].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ',''))
else: else:
amount= float(tds[4].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ','')) amount= float(tds[4].text.strip().replace('.','').replace(',','.').replace(u"\u00A0",'').replace(' ',''))
operation=Operation(len(self.operations)) operation=Operation(len(self.operations))
operation.date=d operation.date=d
operation.label=label operation.label=label
operation.amount=amount operation.amount=amount
self.operations.append(operation) self.operations.append(operation)
done=True
break
if done:
break
def get_operations(self): def get_operations(self):
return self.operations return self.operations