Dodaj 'weather.sh'
This commit is contained in:
parent
056e04aa9f
commit
11d3a0e1b1
55
weather.sh
Normal file
55
weather.sh
Normal file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
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;;
|
||||
?) echo "Niepoprawna opcja: -$OPTARG"
|
||||
exit ;;
|
||||
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
|
||||
echo "Kraj $(echo $JSON | jq -r '.location.country')"
|
||||
echo "Miasto $(echo $JSON | jq -r '.location.name')"
|
||||
if $FAHRENHEIT == true
|
||||
then
|
||||
echo "Temperatura $(echo $JSON | jq -r '.current.temp_f') °F"
|
||||
else
|
||||
echo "Temperatura $(echo $JSON | jq -r '.current.temp_c') °C"
|
||||
fi
|
||||
if $FAHRENHEIT == true
|
||||
then
|
||||
echo "Temperatura odczuwalna $(echo $JSON | jq -r '.current.feelslike_f') °F"
|
||||
else
|
||||
echo "Temperatura odczuwalna $(echo $JSON | jq -r '.current.feelslike_c') °C"
|
||||
fi
|
||||
echo "Predkosc wiatru $(echo $JSON | jq -r '.current.wind_kph') km/h"
|
||||
echo "Cisnienie $(echo $JSON | jq -r '.current.pressure_mb') hPa"
|
||||
echo "Wilgotnosc $(echo $JSON | jq -r '.current.humidity') %"
|
||||
}
|
||||
if $DYNAMIC == true
|
||||
then
|
||||
for ((;;));
|
||||
do
|
||||
weather
|
||||
sleep 300
|
||||
done
|
||||
else
|
||||
|
||||
weather
|
||||
fi
|
Loading…
Reference in New Issue
Block a user