You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
spacefrogg-overlay/gledger/gledger-camt-csv

41 lines
1.1 KiB

#!/bin/sh
# Sparkasse Germany CAMT CSV format
# Sparkasse Germany VISA CSV format
set -e
[ $# -ge 2 ] || { printf "Usage: gledger-camt-csv [-visa | -camt] CSV ACCOUNT\n">&2; exit 1; }
CAMT_HDR=",date,posted,,note,,,,,,,payee,pIBAN,pBIC,amount,,"
VISA_HDR=",date,posted,oAmount,oCommodity,,amount,,payee,note,,,,,,"
HDR=$CAMT_HDR
case $1 in
-visa) shift
HDR=$VISA_HDR
;;
-camt) shift
HDR=$CAMT_HDR
;;
esac
DATE_FMT="%d.%m.%y"
INFILE=$1
_INDIR=$(dirname "$INFILE")
if [ "${_INDIR##/}" != "new" ]; then
printf "Error: Expecting input file in new/ of a maildir-like directory structure\n" >&2
exit 1
fi
BASEDIR=$(dirname $1)/..
BASEDIR=$(realpath "$BASEDIR")
MANGLED=$(mktemp -p $BASEDIR/tmp/ mangled-XXXXXX.csv)
OUTFILE=$BASEDIR/tmp/$(basename "${INFILE%.CSV}.ledger")
{ echo "$HDR"; tail -n+2 "$INFILE"; } |
sed -e 's/";"/","/g' |
iconv -f ISO-8859-1 -t UTF-8 >$MANGLED
gledger convert "$MANGLED" --input-date-format "$DATE_FMT" --invert --rich-data --account $2 >$OUTFILE
echo "$BASEDIR/new/"$(basename "$OUTFILE") >&2
rm -f "$MANGLED"
mv "$INFILE" "$BASEDIR/cur"
mv "$OUTFILE" "$BASEDIR/new"