#!/bin/bash

WATCH_DIR="/home/powerbi"

inotifywait -m -e close_write "$WATCH_DIR" --format "%f" | while read FILE
do
    if [[ "$FILE" == *"powerbi_balance"*".xlsx" ]]; then
        echo "Обновился файл $FILE. Конвертация balance..."
        ssconvert "$WATCH_DIR/powerbi_balance (XLSX).xlsx" "$WATCH_DIR/powerbi_balance.csv"
    fi

    if [[ "$FILE" == *"powerbi_consumption"*".xlsx" ]]; then
        echo "Обновился файл $FILE. Конвертация consumption..."
        ssconvert "$WATCH_DIR/powerbi_consumption (XLSX).xlsx" "$WATCH_DIR/powerbi_consumption.csv"
    fi
done
