Skip to content

Instantly share code, notes, and snippets.

@HHRy
Created November 2, 2014 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HHRy/16f2b9c5a427531c9364 to your computer and use it in GitHub Desktop.
Save HHRy/16f2b9c5a427531c9364 to your computer and use it in GitHub Desktop.
Quick and dirty script to convert Shinsei Power Direct "CSV" files into QIF files for importing into applications
#!/usr/bin/env ruby
#coding: SJIS
require 'rubygems'
require 'qif'
require 'csv'
file_path = ARGV[0]
bank_file = IO.read(file_path).force_encoding('utf-8')
bank_file = CSV.parse(bank_file, col_sep: "\t")
Qif::Writer.open("satement.qif", type = 'Bank', format = 'dd/mm/yyyy') do |qif|
bank_file.each do |row|
next if ( row.empty? || row[0] == "Activity For" || row[0] == "Current Balance" || row[0] == "Start Date" || row[0] == "Value Date" )
row.each { |value| value.to_s.gsub!(/^\s+|\s+$/,'') }
date = row[0].split("/").reverse.join("/")
qif << Qif::Transaction.new(
:date => date,
:amount => row[3].nil? ? row[4].to_f : -row[3].to_f,
:memo => row[1],
:payee => row[2]
)
end
end
source "https://rubygems.org"
gem "qif"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment