#!/bin/bash

# simple script to read weather from airport code and return it for display in xmobar

weather=$(weather-report "$1" -m --no-cache -n | \
        grep 	-e '\[' \
        -e 'Temp' | \
        sed 	-e 's/\[using result //' \
        -e 's/,.*\]//' \
        -e 's/Temp.*: //' \
        -e 's/ C//' \
    -e 's/   //')

readarray -t y <<< "$weather"

loc=${y[0]}
temp=${y[1]}
color=""

if ((temp > 30))
then
    color="#ff5555"
elif ((temp > 25))
then
    color="#ffb86c"
elif ((temp > 20))
then
    color="#f1fa8c"
elif ((temp > 10))
then
    color="#50fa7b"
else
    color="#8be9fd"
fi

echo -e "<fc=#ff79c6>$loc <fc=$color>$temp</fc>C</fc>"
