#!/usr/bin/env bash

# -------------------------------------
# --- Given month, specific dates
# -------------------------------------

# for dt in 20250528 20250529 20250530 20250531; do
# 	rsync -ahvv cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/crypto/sim/2025/2025-05/${dt}.*.gz ./
# done
# -------------------------------------

# -------------------------------------
# --- Current month - all files
# -------------------------------------
cd $(realpath $(dirname $0))/..
mkdir -p ./data/crypto
pushd ./data/crypto

Cmd="rsync -ahvv cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/crypto/sim/*.gz ./"
echo $Cmd
eval $Cmd
# -------------------------------------

for srcfname in $(ls *.db.gz); do
    dt="${srcfname:0:8}"
    tgtfile=${dt}.mktdata.ohlcv.db
    echo "${srcfname} -> ${tgtfile}"

    Cmd="gunzip -c $srcfname > temp.db"
    echo $Cmd
    eval $Cmd
    Cmd="rm -f ${tgtfile} && sqlite3 temp.db \".dump md_1min_bars\" | sqlite3  ${tgtfile} && rm ${srcfname}"
    echo $Cmd
    eval $Cmd
done
rm temp.db
popd
