From 8c100e72fd68c607842aa2048fb7ca701b18f5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Tue, 11 Apr 2023 20:11:29 +0200 Subject: [PATCH] Add license, make atomic, handle wget failures. --- fetch_fio.sh | 76 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/fetch_fio.sh b/fetch_fio.sh index d5c143a..11db84e 100644 --- a/fetch_fio.sh +++ b/fetch_fio.sh @@ -1,21 +1,63 @@ -#!/bin/bash +#!/bin/sh +# +# mailman.scm +# +# Mailman management interface +# +# ISC License +# +# Copyright 2023 Brmlab, z.s. +# Jan Hrach +# Dominik Pantůček +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# REST API endpoint +APIURI=https://www.fio.cz/ib_api/rest + +# Each line should contain account number and Fio API token as first +# two non-whitespace strings. The rest of each line is ignored. There +# must be no leading whitespace. while read accnt; do - ACCNO=`echo $accnt|cut -d ' ' -f 1` - APIKEY=`echo $accnt|cut -d ' ' -f 2` - echo "Processing account $ACCNO" + # Extract account number and Fio token + ACCNO=${accnt%% *} + accrest=${accnt#* } + APIKEY=${accrest%% *} + + # Log action + echo "Processing account $ACCNO" + + # mv $ACCNO.csv $ACCNO.csv.old - mv $ACCNO.csv $ACCNO.csv.old - - # fetch CSV from bank - for i in `seq 1 3`; do - wget https://www.fio.cz/ib_api/rest/periods/${APIKEY}/2015-01-01/2025-01-31/transactions.csv -O $ACCNO.csv - if [ -s $ACCNO.csv ]; then - echo OK - break - else - echo Failed download, retrying in 5 s - sleep 5 - fi - done + # Fetch CSV from bank + CSVNAME=$ACCNO.csv + 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 [ -s $CSVNAME.tmp ] ; then + echo OK + cp $CSVNAME $CSVNAME.old + mv $CSVNAME.tmp $CSVNAME + break + else + echo Download successfull but empty or non-existing result. + echo Retrying in 5 s. + fi + else + echo Failed download, retrying in 5 s. + sleep 5 + fi + done done < apikey.ntlm