updated on Wed Jan 11 08:01:35 UTC 2012
[aur-mirror.git] / cweather / cweather
blobc67161749c8f8e0c2149e8157f3ce6b338729765
1 #!/bin/sh
3 # Author: Xiwen Cheng <x@cinaq.com>
4 # Description: Fetch current weather conditions from google API and print them nicely in colors
6 # load config
7 if [ -x ~/.cweatherrc ]; then
8 . ~/.cweatherrc
9 else
10 . /etc/cweatherrc
13 # allow overrides
14 if [ "x$1" != "x" ]; then
15 city=$1
17 if [ "x$2" != "x" ]; then
18 locale=$2
20 if [ "x$3" != "x" ]; then
21 metric=$3
24 # sanity check
25 if [ -z $city ]; then
26 echo ERROR: no city defined
27 exit 1;
29 if [ -z $locale ]; then
30 echo ERROR: no locale defined
31 exit 1;
33 if [ -z $metric ]; then
34 echo ERROR: no metric defined
35 exit 1;
38 # fetch
39 curl -s -A 'Mozilla/4.0' 'http://www.google.com/ig/api?weather='$city'&hl='$locale > $file
41 # parse
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)}'`
47 else
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)}'`
54 # cleanup
55 #rm $file
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"