Browse files

xml data fixes

  • Loading branch information...
1 parent 632ed5f commit dfac54f9125c3cce4ae4ff7f461d5a8a057318f8 @djmuhlestein committed Jan 22, 2009
Showing with 16 additions and 5 deletions.
  1. +7 −4 src/csv2ofx/__init__.py
  2. +9 −1 src/csv2ofx/csvutils.py
View
11 src/csv2ofx/__init__.py
@@ -127,15 +127,18 @@ def OnExport(self,evt):
dlg.Destroy();
mapping=self.mappings.GetClientData(self.mappings.GetSelection())
+
grid=self.grid_table
accounts={}
+ today = datetime.now().strftime('%Y%m%d')
for row in range(self.grid_table.GetNumberRows()):
# which account
uacct="%s-%s" % (mapping['BANKID'](row,grid), mapping['ACCTID'](row,grid))
acct = accounts.setdefault(uacct,{})
acct['BANKID'] = mapping['BANKID'](row,grid)
- acct['ACCTID'] = mapping['ACCTID'](row,grid)
+ acct['ACCTID'] = mapping['ACCTID'](row,grid)
+ acct['TODAY'] = today
currency = acct.setdefault('CURDEF',mapping['CURDEF'](row,grid))
if currency != mapping['CURDEF'](row,grid):
print "Currency not the same."
@@ -146,7 +149,7 @@ def OnExport(self,evt):
# output
- today = datetime.now().strftime('%Y%m%d')
+
out=open(path,'w')
out.write (
@@ -181,8 +184,8 @@ def OnExport(self,evt):
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
- <DTSTART></DTSTART>
- <DTEND></DTEND>
+ <DTSTART>%(TODAY)s</DTSTART>
+ <DTEND>%(TODAY)s</DTEND>
""" % acct
)
View
10 src/csv2ofx/csvutils.py
@@ -44,11 +44,19 @@ def GetColPos(self,col_name):
return self.col_map[col_name]
+
+def xmlize(dat):
+ """
+ Xml data can't contain &,<,>
+ replace with &amp; &lt; &gt;
+ Get newlines while we're at it.
+ """
+ return dat.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('\r\n',' ').replace('\n',' ')
def fromCSVCol(row,grid,col_name):
"""
Uses the current row and the name of the column to look up the value from the csv data.
"""
- return grid.GetValue(row,grid.GetColPos(col_name))
+ return xmlize(grid.GetValue(row,grid.GetColPos(col_name)))

0 comments on commit dfac54f

Please sign in to comment.