#!/bin/bash # if ping -c 1 google.com; then data="/var/www/hardbrugg.ch/data" query="$(shuf -i 10000-99999 -n 1)" ## Read old data atemp_old="$(cat $data/atemp.data)" depth_old="$(cat $data/depth.data)" disch_old="$(cat $data/disch.data)" wtemp_old="$(cat $data/wtemp.data)" # Get new data ## Air Temp curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" -s https://www.wetteronline.ch/wettertrend/zuerich | grep -o -P '.{0,1}current-temperature.{0,11}' | grep -Eo '\-?[0-9]*' | tail -n 1 > "$data"/atemp.data & ## Depth curl -s https://www.ag.ch/app/hydrometrie/station/?id=11626 | grep -m 9 td | tail -n 1 | grep -Eo '[0-9][0-9][0-9].[0-9][0-9]' | awk '{print $1-398}' > "$data"/depth.data & ## Discharge curl -s --user-agent "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/538.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" https://hydroproweb.zh.ch/Listen/AktuelleWerte/aktuelle_werte.html | grep -A 3 Unterhard | grep nbsp | grep -Eo '[0-9]*[.][0-9]*' | sed 's/\.//' > "$data"/disch.data & ## Water Temp curl -s https://hydroproweb.zh.ch/Listen/AktuelleWerte/AktWassertemp.html | grep -A 3 Letten | grep '' | grep -Eo '[0-9]*\.[0-9]' > "$data"/wtemp.data & ## Weather curl -s -N wttr.in/zuerich > $data/wttr.dataraw && grep -m 2 -Eo "[A-Z][a-z][a-z]* *[A-Za-z]* *[A-Za-z]* *[A-Za-z]*" "$data"/wttr.dataraw | tail -n 1 > "$data"/wttr.data & ## Wait for data to be fetched wait ## Generate Visitor Number #visit_num="$(shuf -i 111111-420069 -n 1)" # Read new data atemp_new="$(cat $data/atemp.data)" depth_new="$(cat $data/depth.data)" disch_new="$(cat $data/disch.data)" wtemp_new="$(cat $data/wtemp.data)" # Write plot data echo "$(date +%Y%m%d%H%M) $atemp_new" >> "$data"/atemp.plot echo "$(date +%Y%m%d%H%M) $depth_new" >> "$data"/depth.plot echo "$(date +%Y%m%d%H%M) ${disch_new}0" >> "$data"/disch.plot echo "$(date +%Y%m%d%H%M) $wtemp_new" >> "$data"/wtemp.plot # Clean plot data and create plot images current_date=$(date +%Y%m%d%H%M) cutoff_date=$(date -d "1 week ago" +%Y%m%d%H%M) plots="atemp depth disch wtemp" for plot in $plots do awk -v cutoff="$cutoff_date" '$1 >= cutoff' "$data"/"${plot}".plot > "$data"/tempfile.txt && mv "$data"/tempfile.txt "$data"/"${plot}".plot gnuplot -c "$data"/plot.gp "$data"/"${plot}".plot "$data"/"${plot}".png done find "$data" -type f -name "*.png" -exec cp {} /var/www/hardbrugg.ch/html/img/ \; # Compare old and new data ## Air Temp if [ $atemp_old -lt $atemp_new ] then echo "${atemp_new}° C ↗" > "$data"/atemp.datatrend elif [ $atemp_old -gt $atemp_new ] then echo "${atemp_new}° C ↘" > "$data"/atemp.datatrend else echo "${atemp_new}° C ➡" > "$data"/atemp.datatrend fi ## Depth if (( $(echo "$disch_old < $disch_new" | bc -l) )) then echo "${depth_new} m ↗" > "$data"/depth.datatrend elif (( $(echo "$disch_old > $disch_new" | bc -l) )) then echo "${depth_new} m ↘" > "$data"/depth.datatrend else echo "${depth_new} m ➡" > "$data"/depth.datatrend fi ## Discharge if (( $(echo "$disch_old < $disch_new" | bc -l) )) then echo "${disch_new}0 L ↗" > "$data"/disch.datatrend elif (( $(echo "$disch_old > $disch_new" | bc -l) )) then echo "${disch_new}0 L ↘" > "$data"/disch.datatrend else echo "${disch_new}0 L ➡" > "$data"/disch.datatrend fi ## Water Temp if (( $(echo "$wtemp_old < $wtemp_new" | bc -l) )) then echo "${wtemp_new}° C ↗" > "$data"/wtemp.datatrend elif (( $(echo "$wtemp_old > $wtemp_new" | bc -l) )) then echo "${wtemp_new}° C ↘" > "$data"/wtemp.datatrend else echo "${wtemp_new}° C ➡" > "$data"/wtemp.datatrend fi # Determine Danger Level disch_dng="$(cat $data/disch.data)" if [ $disch_dng -le 35000 ] then dangr="color:#00FF00\">1" elif [ $disch_dng -gt 35000 ] && [ $disch_dng -le 45000 ] then dangr="color:#FFFF00\">2" elif [ $disch_dng -gt 45000 ] && [ $disch_dng -le 53000 ] then dangr="color:#FFA500\">3" elif [ $disch_dng -gt 53000 ] && [ $disch_dng -le 60000 ] then dangr="color:#FF0000\">4" else dangr="color:#9A0000\">5" fi # Read current data atemp="$(cat $data/atemp.datatrend)" depth="$(cat $data/depth.datatrend)" disch="$(cat $data/disch.datatrend)" wtemp="$(cat $data/wtemp.datatrend)" utime="$(ls -la $data/atemp.data | awk '{print $8 }')" wttr="$(cat $data/wttr.data)" # Write index.html echo -e " hardbrugg.ch

🗺 📧

Made with bash. No cookies, no bullshit.

Updated every 20 minutes, curves show past week.

Using open data from:

Thank you!

Updated at ${utime}

$wttr

Danger Level

Air Temperature

${atemp}

Water Temperature

${wtemp}

Discharge per Second

${disch}

Depth

≈${depth}

\"Looks
" > /var/www/hardbrugg.ch/html/index.html else logger -i "ping failed, skipping data aggregation." exit 1 fi # EOF