Created
June 4, 2020 18:48
-
-
Save rietta/2cf71dd59abfa01a004c391a20d967d9 to your computer and use it in GitHub Desktop.
American Express updated their online banking interface and provides an XML-based QFX format that the GnuCash updater cannot import. This Ruby script converts the new format back to the QFXSGML format that GnuCash knows how to import. Experimental; use at your own risk. It works for me.
This file contains 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 | |
# frozen_string_literal: true | |
# Convert new American Express QFX files (since June 2020) to older SGML format | |
# that GnuCash can import. | |
require 'nokogiri' | |
def show_usage | |
warn 'Usage: amex-ofx-downgrader.rb /path/to/source/file.qfx /path/to/output.qfx' | |
exit 1 | |
end | |
show_usage unless ARGV.count == 2 | |
source_file = ARGV.first | |
unless File.exist?(source_file) | |
warn "Input file #{source_file} does not exist." | |
show_usage | |
end | |
output_file = ARGV.last | |
if File.exist?(output_file) | |
warn "Output file #{output_file} ALREADY EXISTS! Wont overwrite." | |
show_usage | |
end | |
doc = Nokogiri::XML.parse(File.read(source_file)) | |
File.open(output_file, 'wb') do |out| | |
out.puts <<~HEADER | |
OFXHEADER:100 | |
DATA:OFXSGML | |
VERSION:102 | |
SECURITY:NONE | |
ENCODING:UTF8 | |
CHARSET:1252 | |
COMPRESSION:NONE | |
OLDFILEUID:NONE | |
NEWFILEUID:NONE | |
HEADER | |
out.puts '<OFX>' | |
out.puts doc.xpath('//SIGNONMSGSRSV1').to_xml | |
out.puts doc.xpath('//CREDITCARDMSGSRSV1').to_xml | |
out.puts '</OFX>' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment