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