#! /usr/local/bin/zsh # # this file: # https://dataswamp.org/~incal/sth/scripts/elem # # weather service: # https://github.com/chubin/wttr.in/blob/master/README.md # # script example run: # $ elem Uppsala # Uppsala +12C 100% →1.1m/s 1022hPa {02:30 ↑03:48 12:46 ↓21:45 23:04} clear [[ $# != 1 ]] && exit if [[ $1 == "help" ]]; then echo "weather in CITY. output: city time-offset temperature relative-humidity [precipitation] wind-direction/speed pressure dawn-sunrise-zenit-sunset-dusk summary" exit fi city=$1 wttr_url="https://wttr.in" opts="%l+%T+%t+%h+%p+%w+%P+\{%D+↑%S+%z+↓%s+%d\}+%C" frmt="format=${opts}" url="${wttr_url}/${city}?M&${frmt}\n" done=$(curl -s $url | sed -e ' s/ shower//; s/0.0mm //; s/0.00m\/s //; s/Clear/clear/; s/Drizzle/drizzle/; s/Fog/fog/; s/Freezing/freezing/; s/Haze/haze/; s/Heavy/heavy/; s/Light/light/; s/Mist/mist/; s/Moderate/moderate/; s/Overcast/overcast/; s/Partly/partly/; s/Patches/patches/; s/Patchy/patchy/; s/Rain/rain/; s/Shower/shower/; s/Snow/snow/; s/Sunny/sunny/; s/°//g') donenosecs=${done//:[0-5][0-9] / } final=${donenosecs//:[0-5][0-9]\}/\}} if [[ $final != '' && $final[1] != $'\n' ]]; then echo $final else echo "out of queries" fi