Parse start year information.
This commit is contained in:
parent
2546f40871
commit
474c5a06fa
1 changed files with 28 additions and 21 deletions
49
fetch_fio.sh
49
fetch_fio.sh
|
@ -105,33 +105,40 @@ log "$0" ======== started ========
|
||||||
# two non-whitespace strings. The rest of each line is ignored. There
|
# two non-whitespace strings. The rest of each line is ignored. There
|
||||||
# must be no leading whitespace.
|
# must be no leading whitespace.
|
||||||
while read accnt; do
|
while read accnt; do
|
||||||
# Extract account number and Fio token
|
# Extract account number, Fio token and starting year
|
||||||
ACCNO=${accnt%% *}
|
ACCNO=${accnt%% *}
|
||||||
accrest=${accnt#* }
|
accrest=${accnt#* }
|
||||||
APIKEY=${accrest%% *}
|
APIKEY=${accrest%% *}
|
||||||
|
accrest2=${accrest#* }
|
||||||
|
YEAR=${accrest2%% *}
|
||||||
|
|
||||||
# Log action
|
# Check starting year before attempting partial downloads
|
||||||
log "Processing account $ACCNO"
|
if [ -z "$YEAR" ] ; then
|
||||||
|
log "Missing start year for account $ACCNO"
|
||||||
# Fetch CSV from bank
|
else
|
||||||
CSVNAME="$BANK_DIR/$ACCNO.csv"
|
# Log action
|
||||||
for i in `seq 1 3` ; do
|
log "Processing account $ACCNO starting $YEAR"
|
||||||
if wget -q "${APIURI}/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv" -O "$CSVNAME.tmp" ; then
|
|
||||||
if [ -s "$CSVNAME.tmp" ] ; then
|
# Fetch CSV from bank
|
||||||
log Download OK
|
CSVNAME="$BANK_DIR/$ACCNO.csv"
|
||||||
cp "$CSVNAME" "$CSVNAME.old"
|
for i in `seq 1 3` ; do
|
||||||
mv "$CSVNAME.tmp" "$CSVNAME"
|
if wget -q "${APIURI}/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv" -O "$CSVNAME.tmp" ; then
|
||||||
log Finished
|
if [ -s "$CSVNAME.tmp" ] ; then
|
||||||
break
|
log Download OK
|
||||||
|
cp "$CSVNAME" "$CSVNAME.old"
|
||||||
|
mv "$CSVNAME.tmp" "$CSVNAME"
|
||||||
|
log Finished
|
||||||
|
break
|
||||||
|
else
|
||||||
|
log Download successfull but empty or non-existing result.
|
||||||
|
log Retrying in 5 s.
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
log Download successfull but empty or non-existing result.
|
log Failed download, retrying in 5 s.
|
||||||
log Retrying in 5 s.
|
sleep 5
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
log Failed download, retrying in 5 s.
|
fi
|
||||||
sleep 5
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done < "$APIKEYS_FILE"
|
done < "$APIKEYS_FILE"
|
||||||
|
|
||||||
# Mark
|
# Mark
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue