Drop python2 support.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/6/head r14.1.0
Slávek Banko 1 year ago
parent 08ab6ec214
commit d09e55dfbb
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -19,32 +19,32 @@
#* * #* *
#***************************************************************************/ #***************************************************************************/
# #
# *** NOTE *** # *** NOTE ***
# It may be necessary to remove the second line, before running. # It may be necessary to remove the second line, before running.
# It may be necessary also, to change the currency symbol if your file # It may be necessary also, to change the currency symbol if your file
# includes one. # includes one.
# #
# Simple utility to convert a csv format file, as from a bank, to qif # Simple utility to convert a csv format file, as from a bank, to qif
# format for KMyMoney2. There is no standard for the layout of such a # format for KMyMoney2. There is no standard for the layout of such a
# file, but generally there will be a header line which indicates the # file, but generally there will be a header line which indicates the
# layout of the fields within the file. Even then though, the order of # layout of the fields within the file. Even then though, the order of
# the columns may vary. It is assumed, though, that the first column # the columns may vary. It is assumed, though, that the first column
# will contain the date, in 'dd MM yy' format, 'MM' being the month # will contain the date, in 'dd MM yy' format, 'MM' being the month
# name or number. # name or number.
# The second column is the detail. The third and fourth columns are # The second column is the detail. The third and fourth columns are
# assumed to be debits and credits. Even fron the same bank, these # assumed to be debits and credits. Even fron the same bank, these
# columns may be reversed, but the script handles this. Alternatively, # columns may be reversed, but the script handles this. Alternatively,
# the third column may be the amount. There may also be additional # the third column may be the amount. There may also be additional
# columns, such as current balance, but these are all ignored. # columns, such as current balance, but these are all ignored.
# Apart from the header line, there are likely to be other lines, with # Apart from the header line, there are likely to be other lines, with
# account number, balance details, etc. These are skipped. # account number, balance details, etc. These are skipped.
# #
# First, make the script executable: chmod u+x csvbankinyqif.py . # First, make the script executable: chmod u+x csvbankinyqif.py .
# The script should be added to the KMM QIF import profile. In KMM, open # The script should be added to the KMM QIF import profile. In KMM, open
# Tools/QIF Profile Editor and click on 'New' at the bottom. then enter a # Tools/QIF Profile Editor and click on 'New' at the bottom. then enter a
# name, such as csvbank, then click 'OK'. Next, click on that name in the # name, such as csvbank, then click 'OK'. Next, click on that name in the
# next window, and open the Filter tab. For the 'Input filter location', # next window, and open the Filter tab. For the 'Input filter location',
# select the location you chose for the script file. For the Input filter # select the location you chose for the script file. For the Input filter
# file type, enter *.csv, or whatever extension your data file has. # file type, enter *.csv, or whatever extension your data file has.
# Finally, click 'OK'. # Finally, click 'OK'.
# When ready, select File/Import/QIF, and browse to your data file, then # When ready, select File/Import/QIF, and browse to your data file, then
@ -55,97 +55,97 @@
mnths=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] mnths=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
currency = '£' currency = '£'
setup = True setup = True
debsfirst = False # credit column is before debit debsfirst = False # credit column is before debit
both = False # only one amount column both = False # only one amount column
print("!Type:Bank") print("!Type:Bank")
while 1: while 1:
try: try:
line=raw_input() line=input()
except:break except:break
if line == "" : continue # empty line if line == "" : continue # empty line
line = line.replace('"','',) # Strip out ' "' quotes line = line.replace('"','',) # Strip out ' "' quotes
line = line.replace(currency,'',) # Strip out '£', etc. symbol line = line.replace(currency,'',) # Strip out '£', etc. symbol
cols = line.split(',') # Seperator between columns cols = line.split(',') # Seperator between columns
if setup: 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 datefound = ((dt > '0') and (dt < '32')) #this looks like a date
hdrfound = (cols[0] == 'Date') hdrfound = (cols[0] == 'Date')
if not datefound and not hdrfound: continue# still in hdrs if not datefound and not hdrfound: continue# still in hdrs
if hdrfound: if hdrfound:
# #
# *** 'Date', so now in header *** # *** 'Date', so now in header ***
# #
hdrfound = False hdrfound = False
#line = line.replace(' ','',) # Strip out spaces in hdr #line = line.replace(' ','',) # Strip out spaces in hdr
cols[2] = cols[2].replace(' ','',) # Strip out spaces in hdr cols[2] = cols[2].replace(' ','',) # Strip out spaces in hdr
if cols[2] == 'Debits': if cols[2] == 'Debits':
debsfirst = True debsfirst = True
continue continue
elif cols[2] == 'Credits': elif cols[2] == 'Credits':
debsfirst = False debsfirst = False
continue continue
elif cols[2] == 'Amount': elif cols[2] == 'Amount':
both = True both = True
continue continue
else: else:
print 'Error in col[2]' print('Error in col[2]')
print '*** Error in header - col 2 s/b Debit, Credit, or Amount' print('*** Error in header - col 2 s/b Debit, Credit, or Amount')
#continue #continue
exit exit
setup ==False setup ==False
# #
# *** Transactions *** # *** Transactions ***
# #
cnum = 0 # First column cnum = 0 # First column
for col in cols: for col in cols:
if cnum > 3: break if cnum > 3: break
# #
# # Process Date # # Process Date
# #
elif cnum == 0: elif cnum == 0:
col =col.replace(' ','/',2) # Change date seperator to '/' col =col.replace(' ','/',2) # Change date seperator to '/'
m = col.split('/') m = col.split('/')
# *** Check if month not numeric # *** Check if month not numeric
mn = m[1][0:3] # Extract month string from field 2 mn = m[1][0:3] # Extract month string from field 2
fld = 2 fld = 2
try: try:
mnth = mnths.index(mn) # Get month number mnth = mnths.index(mn) # Get month number
except ValueError: # Field 2 not a valid month name except ValueError: # Field 2 not a valid month name
mn = m[0][0:3] # .. so try field 1 mn = m[0][0:3] # .. so try field 1
fld = 1 fld = 1
try: try:
mnth = mnths.index(mn) mnth = mnths.index(mn)
except ValueError: # Nor is field 1 except ValueError: # Nor is field 1
dat = ''.join(col) # ..so use as is (numeric) dat = ''.join(col) # ..so use as is (numeric)
else: # Field 1 is month name else: # Field 1 is month name
dat = col[1:3] + str(mnth + 1) + '/' +m[2] dat = col[1:3] + str(mnth + 1) + '/' +m[2]
else: # Field 2 is month name else: # Field 2 is month name
dat = col[0:3] + str(mnth + 1) + '/' +m[2] dat = col[0:3] + str(mnth + 1) + '/' +m[2]
line = 'D' + dat+'\n' line = 'D' + dat+'\n'
# #
# # Detail column # # Detail column
# #
elif cnum == 1: elif cnum == 1:
#col = col.replace('"','') #col = col.replace('"','')
line = line + 'P' + col +'\n' line = line + 'P' + col +'\n'
# #
# # Debit or credit column # # Debit or credit column
# #
elif cnum == 2: elif cnum == 2:
if col != "": if col != "":
if debsfirst == True: # This is Debit column if debsfirst == True: # This is Debit column
col = '-' + col # Mark as -ve col = '-' + col # Mark as -ve
line = line + 'T' + col +'\n' line = line + 'T' + col +'\n'
# #
# # Credit or debit? # # Credit or debit?
# #
elif ((cnum == 3) and (both == False)): elif ((cnum == 3) and (both == False)):
if col != "": if col != "":
if ((debsfirst == False) ): if ((debsfirst == False) ):
col = '-' + col # Mark as -ve col = '-' + col # Mark as -ve
line = line + 'T' + col + '\n' line = line + 'T' + col + '\n'
cnum+=1 cnum+=1
print line + '^' # output this entry print(line + '^') # output this entry

@ -21,15 +21,15 @@
import csv import csv
# *** NOTE *** # *** NOTE ***
# It may be necessary to remove the second line, before running. # It may be necessary to remove the second line, before running.
# Simple script to convert a csv format Prices file, as from later # Simple script to convert a csv format Prices file, as from later
# editions of Quicken, to qif format for KMyMoney2. # editions of Quicken, to qif format for KMyMoney2.
# It and its data files are expected to be in the same directory. # It and its data files are expected to be in the same directory.
# First make the script executable:- chmod u+x csvpricesqif.py # First make the script executable:- chmod u+x csvpricesqif.py
# Run by ''./csvpricesqif.py' . # Run by ''./csvpricesqif.py' .
# You will be prompted to enter input and output filenames, followed # You will be prompted to enter input and output filenames, followed
# by the symbol for the stock. # by the symbol for the stock.
# Input format - "23.12.09","61.62",,, # Input format - "23.12.09","61.62",,,
@ -38,21 +38,21 @@ import csv
# "HJU8.BE",61.62,"23.12.09" # "HJU8.BE",61.62,"23.12.09"
# ^ # ^
fin = raw_input('Please enter the input Prices filename (.csv, .PRN, etc.) : ') fin = input('Please enter the input Prices filename (.csv, .PRN, etc.) : ')
fout = raw_input('Please enter the output filename (add .qif) : ') fout = input('Please enter the output filename (add .qif) : ')
symbol = raw_input('Please enter the symbol for this stock: ') symbol = input('Please enter the symbol for this stock: ')
symbol ='"'+ symbol+'"'# Add " " around symbol symbol ='"'+ symbol+'"'# Add " " around symbol
inputfile = csv.reader(open(fin, 'rb')) inputfile = csv.reader(open(fin, 'rb'))
outputfile = open(fout, 'w') outputfile = open(fout, 'w')
inputfile.next() # Skip header line. Comment out if no header. next(inputfile) # Skip header line. Comment out if no header.
inputfile_list = [] inputfile_list = []
inputfile_list.extend(inputfile) inputfile_list.extend(inputfile)
for data in inputfile_list: for data in inputfile_list:
line = '!Type:Prices\n' line = '!Type:Prices\n'
line = line +symbol +',' + data[1] + ',"' + data[0] + '"\n' + '^\n' line = line +symbol +',' + data[1] + ',"' + data[0] + '"\n' + '^\n'
#print line #print line
outputfile.write(line) outputfile.write(line)

@ -20,10 +20,10 @@
#***************************************************************************/ #***************************************************************************/
import csv import csv
# *** NOTE *** # *** NOTE ***
# It may be necessary to remove the second line, before running. # It may be necessary to remove the second line, before running.
# Simple utility to convert a csv format Securities file, as from later # Simple utility to convert a csv format Securities file, as from later
# editions of Quicken, to qif format for KMyMoney2. # editions of Quicken, to qif format for KMyMoney2.
# It and its data files are expected to be in the same directory. # It and its data files are expected to be in the same directory.
# #
@ -35,11 +35,11 @@ import csv
# These fields are accepted and suffixed with 'M' in the output file. # These fields are accepted and suffixed with 'M' in the output file.
# Anything of importance in them will need to be copy/pasted into KMM. # Anything of importance in them will need to be copy/pasted into KMM.
fin = raw_input('Please enter the input Securities filename (.csv, .PRN, etc.) : ') fin = input('Please enter the input Securities filename (.csv, .PRN, etc.) : ')
fout = raw_input('Please enter the output filename (add .qif) : ') fout = input('Please enter the output filename (add .qif) : ')
line = csv.reader(open(fin, "rb")) line = csv.reader(open(fin, "rb"))
outputfile = open(fout, 'w') outputfile = open(fout, 'w')
line.next() # Skip header line. Comment out if no header. next(line) # Skip header line. Comment out if no header.
line_list = [] line_list = []
line_list.extend(line) line_list.extend(line)
line = "!Option:AutoSwitch\n" line = "!Option:AutoSwitch\n"

Loading…
Cancel
Save