Prepare splitting.
This commit is contained in:
parent
fff8d4b65f
commit
c302247b50
1 changed files with 60 additions and 2 deletions
|
@ -101,8 +101,66 @@ log() {
|
||||||
echo `date '+%Y-%m-%d %H:%M:%S'` "$@"
|
echo `date '+%Y-%m-%d %H:%M:%S'` "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Gets only given header
|
||||||
|
# $1 - path to file
|
||||||
|
# $2 - header name
|
||||||
|
get_header_field() {
|
||||||
|
grep "^$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Splits given file into twelve months
|
||||||
|
split_year() {
|
||||||
|
# Examine name
|
||||||
|
CSVNAME="$1"
|
||||||
|
bname=${CSVNAME##*/}
|
||||||
|
ACCNO=${bname%%-*}
|
||||||
|
rest=${bname##*-}
|
||||||
|
YEAR=${rest%%.*}
|
||||||
|
log Splitting "$CSVNAME" year "$YEAR" account "$ACCNO"
|
||||||
|
|
||||||
|
# Read header
|
||||||
|
accountId=`get_header_field $CSVNAME accountId`
|
||||||
|
bankId=`get_header_field $CSVNAME bankId`
|
||||||
|
currency=`get_header_field $CSVNAME currency`
|
||||||
|
iban=`get_header_field $CSVNAME iban`
|
||||||
|
openingBalance=`get_header_field $CSVNAME openingBalance`
|
||||||
|
closingBalance=`get_header_field $CSVNAME closingBalance`
|
||||||
|
dateStart=`get_header_field $CSVNAME dateStart`
|
||||||
|
dateEnd=`get_header_field $CSVNAME dateEnd`
|
||||||
|
idFrom=`get_header_field $CSVNAME idFrom`
|
||||||
|
idTo=`get_header_field $CSVNAME idTo`
|
||||||
|
|
||||||
|
# Emit months
|
||||||
|
for month in `seq 1 12` ; do
|
||||||
|
MONTH=$month
|
||||||
|
if [ $MONTH -lt 10 ] ; then
|
||||||
|
MONTH=0$MONTH
|
||||||
|
fi
|
||||||
|
MCSVNAME="$BANK_DIR_PARTS/$ACCNO-$YEAR-$MONTH.csv"
|
||||||
|
log $MCSVNAME
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Current year (last in seq)
|
||||||
|
CYEAR=`date +%Y`
|
||||||
|
|
||||||
|
# Process all known accounts
|
||||||
log Started
|
log Started
|
||||||
while read accnt ; do
|
while read accnt ; do
|
||||||
log $accnt
|
# Extract account number and starting year
|
||||||
done
|
ACCNO=${accnt%% *}
|
||||||
|
accrest=${accnt#* }
|
||||||
|
accrest2=${accrest#* }
|
||||||
|
YEAR=${accrest2%% *}
|
||||||
|
|
||||||
|
# Process the account
|
||||||
|
log ==== ACCNO=$ACCNO YEAR=$YEAR
|
||||||
|
|
||||||
|
# Iterate over years
|
||||||
|
for year in `seq $YEAR $CYEAR` ; do
|
||||||
|
CSVNAME="$BANK_DIR_PARTS/$ACCNO-$year.csv"
|
||||||
|
split_year $CSVNAME
|
||||||
|
done
|
||||||
|
done < "$APIKEYS_FILE"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue