Start work on Fio splitter.

This commit is contained in:
Dominik Pantůček 2023-07-29 09:49:38 +02:00
parent b5bd14a477
commit fff8d4b65f
2 changed files with 111 additions and 1 deletions

View file

@ -125,6 +125,7 @@ download_file() {
tmpfname="$fname.tmp"
oldfname="$fname.old"
for i in `seq 1 3` ; do
echo "$url"
if wget -q "$url" -O "$tmpfname" ; then
if [ -s "$tmpfname" ] ; then
log Download OK
@ -139,6 +140,7 @@ download_file() {
log Retrying in 5 s.
fi
else
cat "$tmpfname"
log Failed download, retrying in 5 s.
sleep 5
fi
@ -151,10 +153,10 @@ download_file() {
# $2 - year
# $3 - destination file name
download_year() {
log "Downloading ${APIURI}/periods/.../$year-01-01/$year-12-31/transactions.csv to $fname"
apikey="$1"
year="$2"
fname="$3"
log "Downloading ${APIURI}/periods/.../$year-01-01/$year-12-31/transactions.csv to $fname"
download_file "${APIURI}/periods/$apikey/$year-01-01/$year-12-31/transactions.csv" "$fname"
}

108
fio_splitter.sh Normal file
View file

@ -0,0 +1,108 @@
#!/bin/sh
#
# fio_splitter.sh
#
# Batch splitter of yearly account statements into monthly ones.
#
# ISC License
#
# Copyright 2023 Brmlab, z.s.
# Jan Hrach
# Dominik Pantůček <dominik.pantucek@trustica.cz>
#
# 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.
#
# Configuration defaults - none
CONFIG_FILE="$HOME/.hackerbaserc"
CFG_BANK_DIR=
CFG_APIKEYS_FILE=
ARG_BANK_DIR=
ARG_APIKEYS_FILE=
# Argument parsing
while ! [ -z "$1" ] ; do
case "$1" in
-apikey)
ARG_APIKEYS_FILE="$2"
shift
shift
;;
-bankdir)
ARG_BANK_DIR="$2"
shift
shift
;;
-config)
CONFIG_FILE="$2"
shift
shift
;;
*)
echo "Usage: $0 [-config file] [-apikey file] [-bankdir dir]"
exit 1
;;
esac
done
# Configuration parsing - assumes "dumb" sed which cannot execute
# multiple statements
get_config_value() {
if [ -z "$1" ] ; then
echo "get_config_value() requires parameter name"
exit 1
fi
if [ -r "$CONFIG_FILE" ] ; then
cat "$CONFIG_FILE" \
| sed 's/#.*//' \
| sed 's/^[ \t]*//' \
| grep "^$1" \
| sed 's/^[^ \t]*//' \
| sed 's/^[ \t]*//' \
| sed 's/[ \t]*$//'
fi
}
CFG_BANK_DIR=`get_config_value bank-dir`
CFG_APIKEYS_FILE=`get_config_value apikeys-file`
# Configuration merging
if [ -z "$ARG_BANK_DIR" ] ; then
BANK_DIR="$CFG_BANK_DIR"
else
BANK_DIR="$ARG_BANK_DIR"
fi
if [ -z "$ARG_APIKEYS_FILE" ] ; then
APIKEYS_FILE="$CFG_APIKEYS_FILE"
else
APIKEYS_FILE="$ARG_APIKEYS_FILE"
fi
# Storage for partial account statements
BANK_DIR_PARTS="$BANK_DIR/parts"
if ! [ -d "$BANK_DIR_PARTS" ] ; then
mkdir -p "$BANK_DIR_PARTS"
fi
#
# Very simple "logging" function (stdout should be redirected to log anyway)
log() {
echo `date '+%Y-%m-%d %H:%M:%S'` "$@"
}
log Started
while read accnt ; do
log $accnt
done