Strip spaces from currency amount values before parsing, reverse CSV line order for reading.
parent
861a9d91c5
commit
8a6c9ad031
|
@ -96,14 +96,14 @@ class IBRow(RawTransfer):
|
|||
self.from_name = row[IBField.from_name]
|
||||
self.title = row[IBField.title]
|
||||
|
||||
af = re.compile(r"([0-9]+)\.([0-9]{2}) ([A-Z]+)")
|
||||
m = af.match(row[IBField.amount])
|
||||
af = re.compile(r"([0-9]+)\.([0-9]{2})([A-Z]+)")
|
||||
m = af.match(''.join(row[IBField.amount].split()))
|
||||
if m is None:
|
||||
raise IBParseError("Can't parse amount value \"{}\"".format(row[IBField.amount]), row)
|
||||
a,b,c = m.groups()
|
||||
self.amount = int(a)*100+int(b)
|
||||
self.currency = c
|
||||
m = af.match(row[IBField.balance])
|
||||
m = af.match(''.join(row[IBField.balance].split()))
|
||||
if m is None:
|
||||
raise IBParseError("Can't parse balance value \"{}\"".format(row[IBField.balance]), row)
|
||||
a,b,c = m.groups()
|
||||
|
@ -144,10 +144,8 @@ class IBParser(object):
|
|||
self.fields = []
|
||||
|
||||
def parse(self, snapshot):
|
||||
c = csv.reader(snapshot.splitlines(), delimiter=";")
|
||||
header = [r.decode("utf-8") for r in next(c, None)]
|
||||
if header is None:
|
||||
raise IBParseError("No header in history for {}".format(self.account_number))
|
||||
lines = snapshot.splitlines()
|
||||
header = lines.pop(0).decode("utf-8").split(";")
|
||||
|
||||
for hf in header:
|
||||
try:
|
||||
|
@ -155,6 +153,7 @@ class IBParser(object):
|
|||
except ValueError as e:
|
||||
raise IBParseError("Unexpected field name \"{}\"".format(hf),e)
|
||||
|
||||
c = csv.reader(reversed(lines), delimiter=";")
|
||||
for row in c:
|
||||
if not len(row) == len(self.fields):
|
||||
raise IBParseError("Row has {} fields, {} expected after parsing the header: \"{}\"".format(len(row), len(self.fields), ';'.join(row)))
|
||||
|
|
Loading…
Reference in New Issue