#!/usr/bin/php
//引数から対象地域を設定.引数がなければ,東京の天気を表示
if($argv[1]){
$city = $argv[1];
}else{
$city ='tokyo';
}
$url = 'http://www.google.com/ig/api?weather=' . $city . '&hl=ja';
$content = mb_convert_encoding(file_get_contents($url),'UTF-8', 'Shift-JIS');
$xml = simplexml_load_string($content);
$weather=$xml->weather;
$info = $weather->forecast_information;
$current = $weather->current_conditions;
$str = str_replace('-', '/', $info->forecast_date->attributes()) . "\n";//日付を整形
$str.= "現在: " . $current->condition->attributes() . "\n";
$str.= "気温: " . $current->temp_c->attributes();
for($i=0; $i
forecast_conditions); $i++){
$forecast=$weather->forecast_conditions[$i];
$low = $forecast->low->attributes();
$high = $forecast->high->attributes();
$condition = $forecast->condition->attributes();
if($i==0){
$day = "";
$str.= "(" . $low . "-" . $high . "℃)\n";
$str.= "予報: " . $condition;
}else{
$str.= "\n------------------\n"; //セパレーター
$day = $forecast->day_of_week->attributes() . "曜日";
$str.= $day . "\n" . $condition . "\n" . $low . "-" . $high . "℃";
}
}
$str.= "\n";
echo $str;
?>
MacはすでにPerlもawkもPHPも実装しているので以上をphpファイルとして保存してgeektoolでディレクトリを指定してやればOK。
geektoolには
php /Users/※※※/Documents/geektools/weather/gw.php osaka,osaka
などなど
引数はtokyo,shibuyaなど地域を指定
これで日本語表示可能になるよ。
英語表示でよければややこしいことせずにYahoo.comの天気情報をひっぱってこればOK