3 # Author: Xiwen Cheng <x@cinaq.com>
4 # Description: Fetch current weather conditions from google API and print them nicely in colors
7 if [ -x ~
/.cweatherrc
]; then
14 if [ "x$1" != "x" ]; then
17 if [ "x$2" != "x" ]; then
20 if [ "x$3" != "x" ]; then
26 echo ERROR
: no city defined
29 if [ -z $locale ]; then
30 echo ERROR
: no locale defined
33 if [ -z $metric ]; then
34 echo ERROR
: no metric defined
39 curl
-s -A 'Mozilla/4.0' 'http://www.google.com/ig/api?weather='$city'&hl='$locale > $file
42 city
=`xml sel -t -c "xml_api_reply/weather/forecast_information/city" $file | awk -F\" '{print $(NF-1)}'`
43 condition
=`xml sel -t -c "xml_api_reply/weather/current_conditions/condition" $file | awk -F\" '{print $(NF-1)}'`
45 if [ $metric = "C" ]; then
46 temp
=`xml sel -t -c "xml_api_reply/weather/current_conditions/temp_c" $file | awk -F\" '{print $(NF-1)}'`
48 temp
=`xml sel -t -c "xml_api_reply/weather/current_conditions/temp_f" $file | awk -F\" '{print $(NF-1)}'`
51 wind
=`xml sel -t -c "xml_api_reply/weather/current_conditions/wind_condition" $file | awk -F\" '{print $(NF-1)}'`
52 humidity
=`xml sel -t -c "xml_api_reply/weather/current_conditions/humidity" $file | awk -F\" '{print $(NF-1)}'`
57 # data gathered, now print them; with colors =]
58 echo -e "\E[0;33m$city, \E[0;33m${temp}\E[m\xc2\xb0${metric}"
59 echo -e "\E[0;33m$condition\E[m"
60 echo -e "\E[0;34m$wind\E[m"
61 echo -e "\E[0;34m$humidity\E[m"