2018-01-13 15:13:58 +01:00
|
|
|
#!/bin/bash
|
2018-01-13 15:25:53 +01:00
|
|
|
#przed uruchomieniem nalezy zadeklarowac zmienna srodowiskowa (np declare -x APIXUKEY=<klucz api>) oraz zainstalowac program jq
|
2018-01-13 15:13:58 +01:00
|
|
|
api=$APIXUKEY
|
|
|
|
LOCATION="Poznan"
|
|
|
|
DYNAMIC=false
|
|
|
|
FAHRENHEIT=false
|
|
|
|
while getopts :l:fd OPT;
|
|
|
|
do
|
|
|
|
case $OPT in
|
|
|
|
l) LOCATION="$OPTARG";;
|
|
|
|
d) DYNAMIC=true;;
|
|
|
|
f) FAHRENHEIT=true;;
|
2018-01-25 21:46:59 +01:00
|
|
|
\?) echo "Bledna opcja: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)echo "Opcja -$OPTARG wymaga argumentu" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2018-01-13 15:13:58 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
DATE=$(date -r /tmp/$LOCATION.json +%s)
|
|
|
|
SYSDATE=$(date +%s)
|
|
|
|
if [ $[$DATE+300] -lt $SYSDATE ]
|
|
|
|
then
|
|
|
|
curl "http://api.apixu.com/v1/current.json?key=$api&q=$LOCATION" -o /tmp/$LOCATION.json -#
|
|
|
|
|
|
|
|
fi
|
|
|
|
function weather {
|
|
|
|
|
|
|
|
JSON=$(cat /tmp/$LOCATION.json)
|
|
|
|
clear
|
2018-01-25 21:46:59 +01:00
|
|
|
if [ $FAHRENHEIT != true ]; then
|
|
|
|
echo "Kraj $(echo $JSON | jq -r '.location.country')"
|
|
|
|
echo "Miasto $(echo $JSON | jq -r '.location.name')"
|
|
|
|
echo "Czas lokalny $(echo $JSON | jq -r '.location.localtime')"
|
|
|
|
echo "Temperatura $(echo $JSON | jq -r '.current.temp_c') °C"
|
|
|
|
echo "Temperatura odczuwalna $(echo $JSON | jq -r '.current.feelslike_c') °C"
|
|
|
|
echo "Predkosc wiatru $(echo $JSON | jq -r '.current.wind_kph') km/h"
|
|
|
|
echo "Cisnienie $(echo $JSON | jq -r '.current.pressure_mb') hPa"
|
|
|
|
echo "Opad $(echo $JSON | jq -r '.current.precip_mm') mm"
|
|
|
|
echo "Wilgotnosc $(echo $JSON | jq -r '.current.humidity') %"
|
|
|
|
echo "Ostatnia aktualizacja $(echo $JSON | jq -r '.current.last_updated')"
|
|
|
|
else
|
|
|
|
echo "Kraj $(echo $JSON | jq -r '.location.country')"
|
|
|
|
echo "Miasto $(echo $JSON | jq -r '.location.name')"
|
|
|
|
echo "Czas lokalny $(echo $JSON | jq -r '.location.localtime')"
|
|
|
|
echo "Temperatura $(echo $JSON | jq -r '.current.temp_f') °F"
|
|
|
|
echo "Temperatura odczuwalna $(echo $JSON | jq -r '.current.feelslike_f') °F"
|
|
|
|
echo "Predkosc wiatru $(echo $JSON | jq -r '.current.wind_mph') mph"
|
|
|
|
echo "Cisnienie $(echo $JSON | jq -r '.current.pressure_in') inHg"
|
|
|
|
echo "Opad $(echo $JSON | jq -r '.current.precip_in') inches"
|
|
|
|
echo "Wilgotnosc $(echo $JSON | jq -r '.current.humidity') %"
|
|
|
|
echo "Ostatnia aktualizacja $(echo $JSON | jq -r '.current.last_updated')"
|
|
|
|
fi
|
|
|
|
|
2018-01-13 15:13:58 +01:00
|
|
|
}
|
|
|
|
if $DYNAMIC == true
|
|
|
|
then
|
|
|
|
for ((;;));
|
|
|
|
do
|
|
|
|
weather
|
|
|
|
sleep 300
|
|
|
|
done
|
|
|
|
else
|
|
|
|
|
|
|
|
weather
|
2018-01-25 21:46:59 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|