Skip to content

Commit

Permalink
Fix name/spaces bug
Browse files Browse the repository at this point in the history
Fix spaces in the name causing URL to not load. Flag hide-header still
true in this version, so remove if you want the location printed.
  • Loading branch information
Tom Gregory committed Jul 17, 2014
1 parent c1590da commit 732d1d1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion geekWeather2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,27 @@ fi

cd `dirname $0`

# rawurl code from http://stackoverflow.com/questions/296536/urlencode-from-a-bash-script
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""

for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}

export TEMPLATE_URL='http://forecast.io/embed/#lat=$LAT&lon=$LON&name=$NAME&static-skycons=1&hide-header=1'

export URL=$(echo $TEMPLATE_URL | sed -e "s/\$LAT/$1/" -e "s/\$LON/$2/" -e "s/\$NAME/$3/")
export URL=$(echo $TEMPLATE_URL | sed -e "s/\$LAT/$1/" -e "s/\$LON/$2/" -e "s/\$NAME/$( rawurlencode "$3" )/")

echo "Converting to image"
webkit2png --width=300 --height=150 -F --transparent --delay=5 -o tmpWeather -D /tmp $URL
Expand All @@ -42,3 +60,4 @@ elif [[ $4 == "DARK" ]]; then
fi

exit 0

0 comments on commit 732d1d1

Please sign in to comment.