Fio fetch logging.
This commit is contained in:
parent
d32c20bb1a
commit
b1226fd12c
1 changed files with 19 additions and 6 deletions
25
fetch_fio.sh
25
fetch_fio.sh
|
@ -28,6 +28,15 @@
|
||||||
# REST API endpoint
|
# REST API endpoint
|
||||||
APIURI=https://www.fio.cz/ib_api/rest
|
APIURI=https://www.fio.cz/ib_api/rest
|
||||||
|
|
||||||
|
#
|
||||||
|
# Very simple "logging" function (stdout should be redirected to log anyway)
|
||||||
|
log() {
|
||||||
|
echo `date '+%Y-%m-%d %H:%M:%S'` $@
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mark
|
||||||
|
log $0 ======== started ========
|
||||||
|
|
||||||
# Each line should contain account number and Fio API token as first
|
# Each line should contain account number and Fio API token as first
|
||||||
# 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.
|
||||||
|
@ -38,24 +47,28 @@ while read accnt; do
|
||||||
APIKEY=${accrest%% *}
|
APIKEY=${accrest%% *}
|
||||||
|
|
||||||
# Log action
|
# Log action
|
||||||
echo "Processing account $ACCNO"
|
log "Processing account $ACCNO"
|
||||||
|
|
||||||
# Fetch CSV from bank
|
# Fetch CSV from bank
|
||||||
CSVNAME=$ACCNO.csv
|
CSVNAME=$ACCNO.csv
|
||||||
for i in `seq 1 3` ; do
|
for i in `seq 1 3` ; do
|
||||||
if wget $APIURI/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv -O $CSVNAME.tmp ; then
|
if wget -q $APIURI/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv -O $CSVNAME.tmp ; then
|
||||||
if [ -s $CSVNAME.tmp ] ; then
|
if [ -s $CSVNAME.tmp ] ; then
|
||||||
echo OK
|
log Download OK
|
||||||
cp $CSVNAME $CSVNAME.old
|
cp $CSVNAME $CSVNAME.old
|
||||||
mv $CSVNAME.tmp $CSVNAME
|
mv $CSVNAME.tmp $CSVNAME
|
||||||
|
log Finished
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo Download successfull but empty or non-existing result.
|
log Download successfull but empty or non-existing result.
|
||||||
echo Retrying in 5 s.
|
log Retrying in 5 s.
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo Failed download, retrying in 5 s.
|
log Failed download, retrying in 5 s.
|
||||||
sleep 5
|
sleep 5
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done < apikey.ntlm
|
done < apikey.ntlm
|
||||||
|
|
||||||
|
# Mark
|
||||||
|
log $0 finished
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue