#!/bin/bash startdate="20230614" enddate="20230709" interval=1 username="username" password="password" serialnumber="serialnumber" curl 'http://server-api.growatt.com/login' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-GB,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Origin: http://server-api.growatt.com' -H 'Connection: keep-alive' -H 'Referer: http://server-api.growatt.com/login' --cookie-jar cookies.txt --data-raw "account=${username}&password=${password}&validateCode=&isReadPact=0" --silent while [[ "${startdate}" -le "${enddate}" ]]; do # echo ${startdate} formatdate="$(date -d "${startdate}" +'%Y-%m-%d')" echo "Processing ${formatdate}" curl 'http://server-api.growatt.com/device/exportMIXHistory' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-GB,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Origin: http://server-api.growatt.com' -H 'Connection: keep-alive' -H 'Referer: http://server-api.growatt.com/index' --cookie cookies.txt --data-raw "mixSn=${serialnumber}&startDate=${formatdate}&endDate=${formatdate}&start=1" -o "growatt-export_${formatdate}.xls" --silent # set new start date based on interval startdate="$(date -d "${startdate} + ${interval} days" +'%Y%m%d')" done