#!/bin/bash

#ws info about the weather (in Cincinnati) from accuweather.com
#
# TODO: completely rewrite, probably using openweather APIs
# TODO: make location configurable
# TODO: make temperature unit configurable
#
# @return {Number(degrees Fahrenheit)}: Current temperature in Cincinnati
################################

dir=$(dirname $0)
#source $dir/util.sh
icon=""
full=""
short=""
color="#00FF00"
#status=0

# TODO : pass the url as ${BLOCK_INSTANCE}
URL='https://www.accuweather.com/fr/fr/nice/136420/weather-forecast/136420'


SITE="$(curl -s "$URL")"

temp="$(curl -s $URL | grep -i 'weather' | grep -i 'acm' | grep -i 'dakar' | cut -d ':' -f 7 | cut -c 2,3  )"
temp+="°"

weather="$(curl -s $URL | grep -i 'weather' | grep -i 'acm' | grep -i 'dakar' | grep -i 'text' | cut -d "\"" -f 4)"

# weather="$(echo "$SITE" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $14 }'| head -1)"
# temp="$(echo "$SITE" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $12"°" }'| head -1)"

nightime="$(date| cut -d " " -f 4 | cut -d ":" -f 1 )"

if [[ $temp < 50 && $temp > 24 ]]; then
    icon=""
    color="#ffdb40"
fi

if [[ $temp < 24 && $temp > 18 ]]; then
    icon=""
    color="#40dbFF"
fi
if [[  $temp < 18 && $temp > 0 ]]; then
    icon=""
    color="#aadddd"
fi
if [[ $temp < 30 && $temp > 25 ]]; then
    icon=""
fi



full="$icon $temp $weather"
short="$temp"


echo $full
echo $short
echo $color
exit $status
