2024-05-31 09:17:53 -05:00
#!/bin/bash
while /bin/true; do
( set -e
find /home/schwab/OptionRecorderSchwab/data/ -type f -cnewer lastRun.stamp | grep -v -e '\..TM\.' | sort | while read singleFile; do
echo Processing ${ singleFile } | tee | systemd-cat -t " `basename $0 ` " -p info
2024-08-20 16:22:39 -05:00
symbol = $( pbzip2 -dc " ${ singleFile } " | jq -e -r '.symbol' | tr -d '$' )
2024-05-31 09:17:53 -05:00
timeStamp = $( basename " ${ singleFile } " | cut -c 1-19 | tr '_' ":" )
2024-08-21 11:18:47 -05:00
insertSQL = $( cat <<-EOF
.timeout 10000;
insert into OptionQuotes (
TimeStamp,
Symbol,
Data
) select
datetime( '${timeStamp}' ,'utc' ) ,
'${symbol}' ,
'test'
where not exists ( select 1
from OptionQuotes
where TimeStamp = datetime( '${timeStamp}' ,'utc' )
and Symbol = '${symbol}'
) ;
2024-05-31 09:17:53 -05:00
EOF
)
2024-08-21 11:18:47 -05:00
echo " $insertSQL " | sqlite3 consolidated.sqlite3
2024-05-31 09:17:53 -05:00
touch -r " ${ singleFile } " lastRun.stamp
done ) 2>& 1 | systemd-cat -t " `basename $0 ` " -p debug
set +e
echo filling symbols table | tee | systemd-cat -t " `basename $0 ` " -p info
2024-08-20 16:22:39 -05:00
sqlite3 consolidated.sqlite3 '.timeout 10000' \\ n'insert INTO Symbols select DISTINCT Symbol from OptionQuotes where OptionQuotes.Symbol not in (select Symbol from Symbols);'
2024-05-31 09:17:53 -05:00
inotifywait -e create -r /home/schwab/OptionRecorderSchwab/data/ | tee | systemd-cat -t " `basename $0 ` " -p info
sleep 200 # wait 200 seconds - this should be enough time for all files to finish writing...
done