diff --git a/contrib/fixup-pricepairs.pl b/contrib/fixup-pricepairs.pl new file mode 100755 index 000000000..efffde98d --- /dev/null +++ b/contrib/fixup-pricepairs.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# +# Copyright 2018 Thomas Baumgart +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ---------------------------------------------------------------------- +# +# This tool reads a KMyMoney XML file on stdin and writes it to stdout +# +# While doing so it fixes broken PRICEPAIRs by removing the entries + +my $skip = 0; + +while(<>) { + if ($_ =~ //) { + my $from_id = $2; + my $to_id = $1; + + $skip = 1 if ($to_id =~ /E\d{6}/); + print $_ if ($skip == 0); + + } elsif ($_ =~ /<\/PRICEPAIR>/) { + print $_ if ($skip == 0); + $skip = 0; + + } else { + print $_ if ($skip == 0); + } +} + diff --git a/contrib/getsplitpart.pl b/contrib/getsplitpart.pl new file mode 100755 index 000000000..515ef73b3 --- /dev/null +++ b/contrib/getsplitpart.pl @@ -0,0 +1,91 @@ +#!/usr/bin/perl +# +# Copyright 2019 Thomas Baumgart +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ---------------------------------------------------------------------- +# +# Extract split field values for a specific account and field into a CSV file +# +# The script reads a plain text KMyMoney XML data file on stdin and writes +# the following columns as CSV format on stdout: +# +# transactionId;splitId;[;numeric amount] +# +# in case the selected field is either 'shares' or 'value' the colum 'amount' +# will be added to the output which contains the value in a form that can be +# processed by spreadsheet programs +# +# +# usage: zcat data.kmy | getsplitpart.pl --acc=A000002 --field=shares > output.csv +# + + +my @args = @ARGV; +my $accountid; +my $field; +my $fields = ";shares;value;payee;"; +my @files = (); + +while ($#args >= 0) { + my $a = shift @args; + $accountid = $1 if ($a =~ /--acc=(.*)/); + $field = $1 if ($a =~ /--field=(.*)/); +} + +die ("Field '$field' not supported.") if ($fields !~ /\;$field\;/); +die ("Missing account id. Use --acc= to specify.") if ($accountid eq ""); +die ("Missing field name. Use --field= to specifiy.") if ($field eq ""); + +my $transactionid; +my $splitid; + +# print header line +print "transactionId;splitId;$field"; +print ";amount" if ($field =~ /^(shares|value)$/); +print "\n"; + +while() { + if ($_ =~ /