#!/usr/bin/perl # Copyright 2005, Jason Boxman. # Released into the PUBLIC DOMAIN. use strict; use warnings; # Parse OFX/QFX and normalize Payee fields. # Unless an entry exists in gcupdate.conf, the default # is to extract the payee field, then # # * Uppercase each word # * Drop the last word if it is <= 2 characters # * Strip any #\d+ for POS systems identifying specific locations # * Strip trailing spaces # # I find the above generally works well enough without having many # entries in gcupdate.conf. my $cfg = 'gcupdate.conf'; # Entries should be of the form # pretty name . statement name # See perldoc Config::General for more details use Config::General; my %config; if( -e $cfg ) { %config = ParseConfig( -ConfigFile => $cfg, -SplitPolicy => 'custom', -SplitDelimiter => '\s*\.\s*' ); } while( my $line = ) { if( $line =~ m/^P/ || $line =~ m//i ) { my $ok = 0; foreach my $n (sort keys %config) { if( ref( $config{$n} ) eq 'ARRAY' ) { warn "Oops, I don't handle multiple instances of the same key right now\n"; } if( $line =~ m/$config{$n}/i ) { # Convert _ to ( ) because I'm lazy $n =~ s/_/ /g; $line =~ s/.*/$n/; $ok = 1; last; } } if( ! $ok ) { my $fix = $line; $fix =~ s/^\s+//g; $fix =~ s///g; chomp( $fix ); # Formatting hack which seems to work for most $fix = substr( $fix, 0, 19 ); $fix =~ s/\s+$//g; $fix =~ s/(#\s?\d+|0+\d+)//g; $fix =~ s/^(deposit|withdrawal).*/$1/i; my @fix = $fix =~ m/(\S+)/g; length( $fix[ scalar(@fix) - 1] ) <= 2 ? pop @fix : undef; @fix = map { lc } @fix; @fix = map { ucfirst } @fix; $fix = join(' ', @fix ); warn "Applying generic for $fix\n"; $line =~ s/.*/$fix/; } } print $line; }