get Tokyo weather from Yahoo

投稿日:

MacのGeekTool
Desktopにお天気を表示させる。東京限定。

Yahoo から、天気の絵をとってくる sh script。

#!/bin/sh
#
# yahoo weather
#
# weather image
URL=`curl --silent "http://weather.yahoo.com/japan/tokyo-prefecture/tokyo-1118370/" | \
grep background:url | sed -e "s/.*background:url('//" -e 's/png.*/png/' | grep -v partner-logo`
curl --silent -o /tmp/weather.png $URL
view raw weather_img.sh hosted with ❤ by GitHub

/tmp/weather.png に現在の天気のpngファイルが出力される。


Yahooから、現在の天気をテキストでとってくる sh script。

#!/bin/sh
#
# yahoo weather
#
# weather text
TEXT_INFO=`curl --silent "http://xml.weather.yahoo.com/forecastrss?p=JAXX0085&u=c" | grep yweather:conditio `
TEXT=`echo $TEXT_INFO | sed -e 's/.*text="//' -e 's/".*//'`
TEMP=`echo $TEXT_INFO | sed -e 's/.*temp="//' -e 's/".*//'`
TEMP=`expr $TEMP - 50`
DATE=`echo $TEXT_INFO | sed -e 's/.*date="//' -e 's/".*//'`
#echo $TEXT $TEMP "&#176 <BR>" $DATE
echo $TEXT ":" $TEMP "C"
echo $DATE
view raw weather_text.sh hosted with ❤ by GitHub

テキストで天気と気温、スナップショット時刻が出力される。

GeekTool で天気の画像を表示させるには、URLに「file://localhost/」を利用。

GeekToolの設定画面.png

完成型がこちら。

YahooWeather.png

夜になると、月になる。

weather_night.png