Move wget retry logic to separate function.
This commit is contained in:
parent
22fc0c0c5a
commit
d9ebe5265c
1 changed files with 33 additions and 18 deletions
49
fetch_fio.sh
49
fetch_fio.sh
|
@ -111,6 +111,37 @@ get_file_date() {
|
|||
echo ${STAT%% *}
|
||||
}
|
||||
|
||||
#
|
||||
# $1 - URI
|
||||
# $2 - output file
|
||||
download_file() {
|
||||
log "Downloading \"$1\" to \"$2\""
|
||||
url="$1"
|
||||
fname="$2"
|
||||
tmpfname="$fname.tmp"
|
||||
oldfname="$fname.old"
|
||||
for i in `seq 1 3` ; do
|
||||
if wget -q "$url" -O "$tmpfname" ; then
|
||||
if [ -s "$tmpfname" ] ; then
|
||||
log Download OK
|
||||
cp "$fname" "$oldfname"
|
||||
mv "$tmpfname" "$fname"
|
||||
log Finished
|
||||
break
|
||||
else
|
||||
log Download successfull but empty or non-existing result.
|
||||
log Retrying in 5 s.
|
||||
fi
|
||||
else
|
||||
log Failed download, retrying in 5 s.
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Current year (last in seq)
|
||||
CYEAR=`date +%Y`
|
||||
|
||||
# Mark
|
||||
log "$0" ======== started ========
|
||||
|
||||
|
@ -134,23 +165,7 @@ while read accnt; do
|
|||
|
||||
# Fetch CSV from bank
|
||||
CSVNAME="$BANK_DIR/$ACCNO.csv"
|
||||
for i in `seq 1 3` ; do
|
||||
if wget -q "${APIURI}/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv" -O "$CSVNAME.tmp" ; then
|
||||
if [ -s "$CSVNAME.tmp" ] ; then
|
||||
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
|
||||
log Failed download, retrying in 5 s.
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
download_file "${APIURI}/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv" "$CSVNAME"
|
||||
fi
|
||||
done < "$APIKEYS_FILE"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue