#!/mnt/local/bin/gawk -f # 漢字コードは Shift-JIS です。 BEGIN { prefecture = "Tokyo"; area = "Tokyo"; # prefecture = "Kanagawa"; # area = "Eastern"; # prefecture = "Saitama"; # area = "Southern"; # prefecture = "Chiba"; # area = "Northwestern"; # prefecture = "Yamanashi"; # area = "Eastern"; cmd = "/mnt/local/bin/wget http://www.yomiuri.co.jp/weather_e/kanto.htm -O - -q"; RS = "[[:space:]]*(>[[:space:]]*<|<|>)[[:space:]]*"; state = 0; i = 1; while ((cmd | getline) > 0 && state >= 0) { if (state == 0 && /size="2"/) state = 1; else if (state ==1 && /b/) state = 2; else if (state == 2 && $0 ~ prefecture) state = 3; else if (state == 3 && /size="1"/) state = 4; else if (state == 4 && $0 ~ area) state = 5; else if (state == 5) { if (/#eeeeee/) state = 6; else if (/size="2"/) state = -1; } else if (state == 6) { if (/img src/) { split($0, field, "wgif/|.gif"); data[i++] = field[2]; } else { gsub(/ /, ""); data[i++] = $0; } state = 5; } } close(cmd); if (strftime("%p", systime()) == "AM") { weather = data[1]; rain = data[2]; temp = data[3]; } else { weather = data[4]; rain = data[5]; temp = data[6]; } sub(/har/, "ハレ", weather); sub(/kum/, "クモ", weather); sub(/ame/, "アメ", weather); sub(/yuk/, "ユキ", weather); sub(/N/, ">", weather); sub(/T/, "/", weather); sub(/h/, "ハレ", weather); sub(/k/, "クモ", weather); sub(/a/, "アメ", weather); sub(/y/, "ユキ", weather); if (weather != "") output = substr(weather rain " " temp, 1, 16); else output = "tenki error"; system("lcd '" output "'"); print output > "/var/camera/tenki.txt"; print output | "nkf -S -j"; }