Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | None | 0 0
  1. city="Poznan"
  2. isDynamic=0
  3. isFarenheit=0
  4.  
  5.  
  6.  
  7.  while getopts ":lfd" choose;
  8.  do
  9.         if [ $choose == "l" ]; then
  10.                 city="$OPTARG";
  11.         elif [ $choose == "f" ]; then
  12.                 isFarenheit=1;
  13.         elif [ $choose == "d" ]; then
  14.                 isDynamic=1;
  15.         fi
  16. done
  17.  
  18. function getData {
  19.   echo $city;
  20.   wget "https://api.apixu.com/v1/current.json?key=547913e948c14692ba3200927171112&q=$city" -O "./temp.json" &> /dev/null
  21.   data=$(cat "./temp.json");
  22. }
  23.  
  24. function getWeather {
  25.     clear  &&  getData;
  26.     echo "Lokalizacja $(echo $data | jq -r '.city.name')";  
  27.  
  28.     if [ $isFarenheit == 1 ] ; then
  29.         echo "$(echo $data | jq -r '.current.temp_f') stopni F";
  30.     else
  31.         echo "$(echo $data | jq -r '.current.temp_c') stopni C";
  32.     fi
  33.  
  34.     echo "$(echo $data | jq -r '.current.pressure_mb') hPa";
  35.     echo "$(echo $data | jq -r '.current.wind_kph') kPh";
  36.     echo "$(echo $data | jq -r '.current.humidity') % wilgotnosci";
  37.     echo "$(echo $data | jq -r '.current.cloud') % zachmurzenia";
  38. }
  39.  
  40. if [ $isDynamic == 0 ] ; then
  41.   while [ 1 ]
  42.   do
  43.      getWeather;
  44.      sleep 5m;
  45.   done
  46. else
  47.     getWeather;
  48.     exit 0
  49. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement