#/usr/bin/bash

# Download multiple files using curl 

URL=https://eye2sky.de/data/asi/imgs

# Start and end of period (exclusive)
START_DATE='2022-04-01'
END_DATE='2022-04-10'

# List of all sites (Do not change)
ALL_SITES="AURIC BARSE BAZWI DOERP EMSTE ESENS ESREF LEEER OLBFE OLCLO OLDLR OLDON OLEMS OLETZ OLFLE OLHOL OLJET OLMAR OLTIR OLTWE OLUOL PAPEN PVAMM PVNOR PVRAS SOEGE VAREL WESTE WITTM"

# Sites selected
SITES="AURIC"

while [[ "$START_DATE" != "$END_DATE" ]]; do
    START_DATE=$(date --date "$START_DATE + 1 day" +"%Y-%m-%d")
    for SITE in ${SITES}; do
        DIRNAME=$(date --date "$START_DATE + 1 day" +"%Y/%m/%d")
        FILENAME=ASI_$(date --date "$START_DATE + 1 day" +"%Y%m%d")_${SITE}.zip
        TARGET_URL=${URL}/${DIRNAME}/${FILENAME}
        echo "Downloading StationID ${SITE} and date ${START_DATE} from $TARGET_URL"
        curl -O $TARGET_URL
    done
done


