#!/bin/bash
## temp-curve.sh# Bash sript by Wüsti (p) 2023-12/2024-01# This file creates a data file by evaluating the OpenWeather JSON file# and creates a temparatue curve of the predictions with gnuplot# like the one the openwethermap widges has.## I use bc to compare temperatur data because the shell commands calculate with# integers and can't operate with real numbers.# bc prompts the errorcode, 0 true, 1 false; so if you need that you test# against that prompt when working non interactive with bc.# I have a ready made gnuplot ini-file, it has all the commands to create the# $TEMPCURVE_PNG.#BIN_DIR="/root/bin/WeatherWidget". $BIN_DIR/WeatherWidget.ini
change (){localVAR=${PREDICTION_TEMP_NIGHT[$j]} PREDICTION_TEMP_NIGHT[$j]=${PREDICTION_TEMP_DAY[$j]} PREDICTION_TEMP_DAY[$j]=$VAR}declare -a PREDICTION_TEMP_DAY
declare -a PREDICTION_TEMP_NIGHT
for i in {0..7}# Alle Vorhersagedaten in ein Array einlesendo PREDICTION_TEMP_DAY[$i]=`jq -r .daily[$i].temp.day $J_SOURCE` PREDICTION_TEMP_NIGHT[$i]=`jq -r .daily[$i].temp.night $J_SOURCE`done# Hier sorgen wir dafür, dass Gnuplot richtig rum zeichnetfor i in 0246# Jedes Gerade gegen das Folgende testendoj=$((i+1))# wenn day jetzt > night jetzt und day morgen > nacht morgen changeif[[$(echo"${PREDICTION_TEMP_DAY[$i]} > ${PREDICTION_TEMP_NIGHT[$i]}"| bc ) -ne 0]]&&[[$(echo"${PREDICTION_TEMP_DAY[$j]} > ${PREDICTION_TEMP_NIGHT[$j]}"| bc ) -ne 0]]then change
fi# wenn day jetzt < night jetzt und day morgen < nacht morgen changeif[[$(echo"${PREDICTION_TEMP_DAY[$i]} < ${PREDICTION_TEMP_NIGHT[$i]}"| bc ) -ne 0]]&&[[$(echo"${PREDICTION_TEMP_DAY[$j]} < ${PREDICTION_TEMP_NIGHT[$j]}"| bc ) -ne 0]]then change
fidonerm $D_FILE >/dev/null 2>&1rm $I_SOURCE_FILE >/dev/null 2>&1# Datendatei für Gnuplot erzeugenfor i in {0..6}# Alle Daten minus 1, da wir mit $i+1 arbeiten, s .u.doj=$((i+1))echo"$i${PREDICTION_TEMP_DAY[$i]}" >> $D_FILEecho"$i${PREDICTION_TEMP_NIGHT[$i]}" >> $D_FILEecho"$j${PREDICTION_TEMP_DAY[$j]}" >> $D_FILEecho"$j${PREDICTION_TEMP_NIGHT[$j]}" >> $D_FILEecho"$i${PREDICTION_TEMP_DAY[$i]}" >> $D_FILEecho"" >> $D_FILEdone# Grafik erzeugengnuplot $RC_FILE
1
2
3
4
5
6
7
8
9
10
#!/bin/sh
#BIN_DIR="/root/bin/WeatherWidget". $BIN_DIR/WeatherWidget.ini
# If we get new data, rebuild HTML filewget "http://api.openweathermap.org/data/2.5/onecall?lat=$MY_LAT&lon=$MY_LON&exclude=minutely,hourly,alerts&units=$MY_UNITS&lang=$MY_LANG&appid=$MY_API_KEY" -O $J_SOURCE$BIN_DIR/weather-content.sh
# One variable data file sourced by WeatherWidget scripts## Openweather.org one-call-3 api variables used by weather-api.sh# Place your one-call api data here:MY_API_KEY="your Openweathermap Key"MY_LANG="your 2 capital letter country code, e.g. DE"MY_UNITS="your temperature units e.g. METRIC"MY_LON="XX.XX" # your longitudeMY_LAT="XX.XXXX" # your latitude# Section to adjust directories and filenames if nescessaryMY_WIND_DIR="km/h aus"TEMPCURVE_PNG="curve.png"WWW_DIR="/var/www/html"WWW_FILE="weather-content.html"I_SOURCE="$WWW_DIR/IMG"J_SOURCE="$WWW_DIR/DATA/wolfenbuettel.json"RC_FILE="$WWW_DIR/DATA/gnuplot.ini"D_FILE="$WWW_DIR/DATA/curve.data"MY_MESSAGE="Letzte Aktualisierung:"HTML_LANG="de"HTML_TITLE="WETTER WOLFENBÜTTEL"# do not changeI_SOURCE_FILE="$I_SOURCE/$TEMPCURVE_PNG"