Created
          November 2, 2014 06:31 
        
      - 
      
- 
        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
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | source "https://rubygems.org" | |
| gem "qif" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment