#!/bin/bash
Location="Poznan"
Dynamic=false
Fahrenheit=false
Api_key="99aab0a02cc2431b910194023170912"
lb="e[94m";
lc="e[96m";
lw="e[97m";
ly="e[33m";
default="e[39m";
while getopts "dl:f" opt; do
case $opt in
d)
Dynamic=true
;;
l)
Location="$OPTARG"
;;
f)
Fahrenheit=true
;;
?)
exit 1
;;
:)
exit 1
;;
esac
done
function download_data {
local File="/tmp/$Location"
local CurrentTime=$(date +%s)
local FileCreationTime=0
if [ -e "$File" ] ; then
FileCreationTime=$(stat -c "%Y" $File)
fi
if (( ( $CurrentTime - $FileCreationTime ) >= 300 )) ; then
Data=$(curl -s "http://api.apixu.com/v1/current.json?key=$Api_key&q=$Location")
if $(echo $Data | jq 'has("error")') ; then
echo "Nie udało się znaleźć takiego miasta. Możesz je wybudować!:)"
exit 1
fi
echo "$Data" > $File
else
Data=$(cat $File)
fi
}
function print_data {
echo -e "$lbu27F0 $lw Miasto $lbu27F0 $lc $(echo $Data | jq -r '.location.name')"
if [ "$Fahrenheit" == true ] ; then
echo -e "$lbu2600 $lw Temperatura $lbu2600 $lc $(echo $Data | jq -r '.current.temp_f') F"
else
echo -e "$lbu2600 $lw Temperatura $lbu2600 $lc $(echo $Data | jq -r '.current.temp_c') C"
fi
echo -e "$lbu2B83 $lw Ciśnienie $lbu2B83 $lc $(echo $Data | jq -r '.current.pressure_mb')"
echo -e "$lbu0f04 $lw Wiatr $lbu0f04 $lc $(echo $Data | jq -r '.current.wind_kph')"
echo -e "$lbu2614 $lw Wilgotność $lbu2614 $lc $(echo $Data | jq -r '.current.humidity')"
echo -e "$lbu2601 $lw Zachmurzenie $lbu2601 $lc $(echo $Data | jq -r '.current.cloud')"
}
if [ "$Dynamic" == true ] ; then
while [ true ]; do
echo -e "$ly==================================================="
download_data
print_data
echo -e "$ly==================================================="
sleep 300;
done
else
download_data
print_data
exit 0
fi
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}