Improve update checks.
This commit is contained in:
parent
5287c17d19
commit
abd9f4aa5b
1 changed files with 15 additions and 12 deletions
27
fetch_fio.sh
27
fetch_fio.sh
|
@ -119,7 +119,6 @@ get_file_date() {
|
|||
# $1 - URI
|
||||
# $2 - output file
|
||||
download_file() {
|
||||
log "Downloading \"$1\" to \"$2\""
|
||||
url="$1"
|
||||
fname="$2"
|
||||
tmpfname="$fname.tmp"
|
||||
|
@ -132,7 +131,7 @@ download_file() {
|
|||
cp "$fname" "$oldfname"
|
||||
fi
|
||||
mv "$tmpfname" "$fname"
|
||||
log Finished
|
||||
log Rename OK
|
||||
break
|
||||
else
|
||||
log Download successfull but empty or non-existing result.
|
||||
|
@ -151,7 +150,11 @@ download_file() {
|
|||
# $2 - year
|
||||
# $3 - destination file name
|
||||
download_year() {
|
||||
download_file "${APIURI}/periods/$1/$2-01-01/$2-12-31/transactions.csv" "$3"
|
||||
log "Downloading ${APIURI}/periods/.../$year-01-01/$year-12-31/transactions.csv to $fname"
|
||||
apikey="$1"
|
||||
year="$2"
|
||||
fname="$3"
|
||||
download_file "${APIURI}/periods/$apikey/$year-01-01/$year-12-31/transactions.csv" "$fname"
|
||||
}
|
||||
|
||||
# Current year (last in seq)
|
||||
|
@ -190,23 +193,23 @@ while read accnt ; do
|
|||
for year in `seq $YEAR $CYEAR` ; do
|
||||
# Check whether it needs fetching
|
||||
CSVNAME="$BANK_DIR_PARTS/$ACCNO-$year.csv"
|
||||
UPDATED=`get_file_date "$CSVNAME"`
|
||||
NYEAR=`expr $year + 1`
|
||||
MINUPD="$NYEAR-01-02"
|
||||
UTS=`date -d $UPDATED +%s`
|
||||
MTS=`date -d $MINUPD +%s`
|
||||
if [ "$UTS" -lt "$MTS" ] ; then
|
||||
log "Update $ACCNO in $year - updated $UPDATED, needs $MINUPD"
|
||||
FILE_DATE=`get_file_date "$CSVNAME"`
|
||||
NEXT_YEAR=`expr $year + 1`
|
||||
MIN_DATE="$NEXT_YEAR-01-02"
|
||||
FILE_TS=`date -d $FILE_DATE +%s`
|
||||
MIN_TS=`date -d $MIN_DATE +%s`
|
||||
if [ "$FILE_TS" -lt "$MIN_TS" ] ; then
|
||||
log "Update $ACCNO in $year - updated $FILE_DATE, needs $MIN_DATE"
|
||||
download_year "$APIKEY" "$year" "$CSVNAME"
|
||||
if [ "$year" -lt "$CYEAR" ] ; then
|
||||
log "Sleeping for 30s before next API usage"
|
||||
sleep 30
|
||||
fi
|
||||
else
|
||||
log "Skipping $ACCNO in $year - already latest"
|
||||
log "Skipping $ACCNO in $year - already latest: $FILE_DATE"
|
||||
fi
|
||||
done
|
||||
done < "$APIKEYS_FILE"
|
||||
|
||||
# Mark
|
||||
log "$0" finished
|
||||
log "$0" ======== finished ========
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue