|
|
|
@ -19,7 +19,7 @@
|
|
|
|
|
#* *
|
|
|
|
|
#***************************************************************************/
|
|
|
|
|
#
|
|
|
|
|
# *** NOTE ***
|
|
|
|
|
# *** NOTE ***
|
|
|
|
|
# It may be necessary to remove the second line, before running.
|
|
|
|
|
# It may be necessary also, to change the currency symbol if your file
|
|
|
|
|
# includes one.
|
|
|
|
@ -55,97 +55,97 @@
|
|
|
|
|
mnths=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
|
|
|
|
currency = '£'
|
|
|
|
|
setup = True
|
|
|
|
|
debsfirst = False # credit column is before debit
|
|
|
|
|
both = False # only one amount column
|
|
|
|
|
debsfirst = False # credit column is before debit
|
|
|
|
|
both = False # only one amount column
|
|
|
|
|
print("!Type:Bank")
|
|
|
|
|
while 1:
|
|
|
|
|
try:
|
|
|
|
|
line=raw_input()
|
|
|
|
|
line=input()
|
|
|
|
|
except:break
|
|
|
|
|
if line == "" : continue # empty line
|
|
|
|
|
line = line.replace('"','',) # Strip out ' "' quotes
|
|
|
|
|
line = line.replace(currency,'',) # Strip out '£', etc. symbol
|
|
|
|
|
if line == "" : continue # empty line
|
|
|
|
|
line = line.replace('"','',) # Strip out ' "' quotes
|
|
|
|
|
line = line.replace(currency,'',) # Strip out '£', etc. symbol
|
|
|
|
|
cols = line.split(',') # Seperator between columns
|
|
|
|
|
if setup:
|
|
|
|
|
#
|
|
|
|
|
# *** SETUP ***
|
|
|
|
|
# *** SETUP ***
|
|
|
|
|
#
|
|
|
|
|
dt = cols[0][0:2] # Might be a date (day)
|
|
|
|
|
dt = cols[0][0:2] # Might be a date (day)
|
|
|
|
|
datefound = ((dt > '0') and (dt < '32')) #this looks like a date
|
|
|
|
|
hdrfound = (cols[0] == 'Date')
|
|
|
|
|
if not datefound and not hdrfound: continue# still in hdrs
|
|
|
|
|
if hdrfound:
|
|
|
|
|
#
|
|
|
|
|
# *** 'Date', so now in header ***
|
|
|
|
|
# *** 'Date', so now in header ***
|
|
|
|
|
#
|
|
|
|
|
hdrfound = False
|
|
|
|
|
#line = line.replace(' ','',) # Strip out spaces in hdr
|
|
|
|
|
cols[2] = cols[2].replace(' ','',) # Strip out spaces in hdr
|
|
|
|
|
#line = line.replace(' ','',) # Strip out spaces in hdr
|
|
|
|
|
cols[2] = cols[2].replace(' ','',) # Strip out spaces in hdr
|
|
|
|
|
if cols[2] == 'Debits':
|
|
|
|
|
debsfirst = True
|
|
|
|
|
continue
|
|
|
|
|
debsfirst = True
|
|
|
|
|
continue
|
|
|
|
|
elif cols[2] == 'Credits':
|
|
|
|
|
debsfirst = False
|
|
|
|
|
continue
|
|
|
|
|
debsfirst = False
|
|
|
|
|
continue
|
|
|
|
|
elif cols[2] == 'Amount':
|
|
|
|
|
both = True
|
|
|
|
|
continue
|
|
|
|
|
both = True
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
print 'Error in col[2]'
|
|
|
|
|
print '*** Error in header - col 2 s/b Debit, Credit, or Amount'
|
|
|
|
|
#continue
|
|
|
|
|
exit
|
|
|
|
|
print('Error in col[2]')
|
|
|
|
|
print('*** Error in header - col 2 s/b Debit, Credit, or Amount')
|
|
|
|
|
#continue
|
|
|
|
|
exit
|
|
|
|
|
setup ==False
|
|
|
|
|
#
|
|
|
|
|
# *** Transactions ***
|
|
|
|
|
# *** Transactions ***
|
|
|
|
|
#
|
|
|
|
|
cnum = 0 # First column
|
|
|
|
|
for col in cols:
|
|
|
|
|
if cnum > 3: break
|
|
|
|
|
#
|
|
|
|
|
# # Process Date
|
|
|
|
|
# # Process Date
|
|
|
|
|
#
|
|
|
|
|
elif cnum == 0:
|
|
|
|
|
col =col.replace(' ','/',2) # Change date seperator to '/'
|
|
|
|
|
m = col.split('/')
|
|
|
|
|
# *** Check if month not numeric
|
|
|
|
|
mn = m[1][0:3] # Extract month string from field 2
|
|
|
|
|
fld = 2
|
|
|
|
|
try:
|
|
|
|
|
mnth = mnths.index(mn) # Get month number
|
|
|
|
|
except ValueError: # Field 2 not a valid month name
|
|
|
|
|
mn = m[0][0:3] # .. so try field 1
|
|
|
|
|
fld = 1
|
|
|
|
|
try:
|
|
|
|
|
mnth = mnths.index(mn)
|
|
|
|
|
except ValueError: # Nor is field 1
|
|
|
|
|
dat = ''.join(col) # ..so use as is (numeric)
|
|
|
|
|
else: # Field 1 is month name
|
|
|
|
|
dat = col[1:3] + str(mnth + 1) + '/' +m[2]
|
|
|
|
|
else: # Field 2 is month name
|
|
|
|
|
dat = col[0:3] + str(mnth + 1) + '/' +m[2]
|
|
|
|
|
line = 'D' + dat+'\n'
|
|
|
|
|
#
|
|
|
|
|
# # Detail column
|
|
|
|
|
col =col.replace(' ','/',2) # Change date seperator to '/'
|
|
|
|
|
m = col.split('/')
|
|
|
|
|
# *** Check if month not numeric
|
|
|
|
|
mn = m[1][0:3] # Extract month string from field 2
|
|
|
|
|
fld = 2
|
|
|
|
|
try:
|
|
|
|
|
mnth = mnths.index(mn) # Get month number
|
|
|
|
|
except ValueError: # Field 2 not a valid month name
|
|
|
|
|
mn = m[0][0:3] # .. so try field 1
|
|
|
|
|
fld = 1
|
|
|
|
|
try:
|
|
|
|
|
mnth = mnths.index(mn)
|
|
|
|
|
except ValueError: # Nor is field 1
|
|
|
|
|
dat = ''.join(col) # ..so use as is (numeric)
|
|
|
|
|
else: # Field 1 is month name
|
|
|
|
|
dat = col[1:3] + str(mnth + 1) + '/' +m[2]
|
|
|
|
|
else: # Field 2 is month name
|
|
|
|
|
dat = col[0:3] + str(mnth + 1) + '/' +m[2]
|
|
|
|
|
line = 'D' + dat+'\n'
|
|
|
|
|
#
|
|
|
|
|
# # Detail column
|
|
|
|
|
#
|
|
|
|
|
elif cnum == 1:
|
|
|
|
|
#col = col.replace('"','')
|
|
|
|
|
line = line + 'P' + col +'\n'
|
|
|
|
|
#col = col.replace('"','')
|
|
|
|
|
line = line + 'P' + col +'\n'
|
|
|
|
|
#
|
|
|
|
|
# # Debit or credit column
|
|
|
|
|
# # Debit or credit column
|
|
|
|
|
#
|
|
|
|
|
elif cnum == 2:
|
|
|
|
|
if col != "":
|
|
|
|
|
if debsfirst == True: # This is Debit column
|
|
|
|
|
col = '-' + col # Mark as -ve
|
|
|
|
|
line = line + 'T' + col +'\n'
|
|
|
|
|
if col != "":
|
|
|
|
|
if debsfirst == True: # This is Debit column
|
|
|
|
|
col = '-' + col # Mark as -ve
|
|
|
|
|
line = line + 'T' + col +'\n'
|
|
|
|
|
#
|
|
|
|
|
# # Credit or debit?
|
|
|
|
|
# # Credit or debit?
|
|
|
|
|
#
|
|
|
|
|
elif ((cnum == 3) and (both == False)):
|
|
|
|
|
if col != "":
|
|
|
|
|
if ((debsfirst == False) ):
|
|
|
|
|
col = '-' + col # Mark as -ve
|
|
|
|
|
line = line + 'T' + col + '\n'
|
|
|
|
|
if col != "":
|
|
|
|
|
if ((debsfirst == False) ):
|
|
|
|
|
col = '-' + col # Mark as -ve
|
|
|
|
|
line = line + 'T' + col + '\n'
|
|
|
|
|
cnum+=1
|
|
|
|
|
print line + '^' # output this entry
|
|
|
|
|
print(line + '^') # output this entry
|
|
|
|
|