#!/bin/sh
if [[ $1 == "" ]]; then
	echo Usage: weather [city name]
	exit
fi
json=$(curl "https://api.openweathermap.org/data/2.5/weather?q=$1&appid=eaeee940cb90e354af08bd8c06ce4ed8&units=metric" -s)
if [[ $(echo $json | jq -r .cod) == "404" ]]; then
	echo Cant find $1!
	exit
fi
icon=$(echo $json | jq -r .weather[0].icon)
ic="${icon:0:2}"
if [[ $ic == "01" ]]; then
cat << "EOF"
    \_____/
   /     \
--|       |-- 
   \_____/
  /       \

EOF
fi
if [[ $ic == "02" ]]; then
cat << "EOF"
    \_____/
   /     \
--|       |-- 
   \_____/
  /       \

EOF
fi
if [[ $ic == "03" ]]; then
cat << "EOF"
   ,.,.,.,
  /       \.,.,.
 /              \
/,.,.,.,.,.,,.,..\ 

EOF
fi
if [[ $ic == "04" ]]; then
cat << "EOF"
   ,.,.,.,
  /       \.,.,.
 /              \
/,.,.,.,.,.,,.,..\ 


EOF
fi
if [[ $ic == "09" ]]; then
cat << "EOF"
   ,.,.,.,
  /       \.,.,.
 /              \
/,.,.,.,.,.,,.,..\ 
  ,    ,     , 
     ,   ,  
   ,        ,  , 


EOF
fi
if [[ $ic == "10" ]]; then
cat << "EOF"
   ,.,.,.,
  /       \.,.,.
 /              \
/,.,.,.,.,.,,.,..\ 
     /       /  /
   /    / / 
/   /       / /   


EOF
fi
if [[ $ic == "11" ]]; then
cat << "EOF"
  __
  \ \
    \ \
  __\ \
  \  __\
   \ \
    \ \
     \/
     
EOF
fi
printf "\033[1m"
echo $json | jq -r .weather[0].description
printf "\033[0m"
echo Temp: $(echo $json | jq -r .main.temp) C
echo Wind speed: $(echo $json | jq -r .wind.speed) m/s


