最近全国雨水较多,写了个查询天气的小脚本,利用google提供的api。 | $city=Read-Host "请输入要查询城市字母全拼" | | $URI = "http://www.google.com/ig/api?hl=zh-cn&weather=$city" | | | | $webclient = new-object net.webclient | | | | try{ | | $proxy = [xml]$webclient.downloadstring($URI) | | } | | catch [Exception]{ | | "连接失败" | | return | | } | | if( $Proxy.xml_api_reply.weather.problem_cause){ | | "没有该城市的天气信息或输入了错误的城市名" | | return | | } | | | | $Temp = $Proxy.xml_api_reply.weather.current_conditions.temp_c.GetAttribute("data") | | | | $Condition = $Proxy.xml_api_reply.weather.current_conditions.Condition.GetAttribute("data") | | | | $humidity = $Proxy.xml_api_reply.weather.current_conditions.humidity.GetAttribute("data") | | | | $wind= $Proxy.xml_api_reply.weather.current_conditions.wind_condition.GetAttribute("data") | | $Forecast=$null | | $Proxy.xml_api_reply.weather.selectNodes("//forecast_conditions") | ForEach-Object { | | $Forecast+= $_.day_of_week.GetAttribute("data") + " " | | $Forecast += $_.low.GetAttribute("data") + " - " + $_.high.GetAttribute("data") | | $Forecast += " " + $_.condition.GetAttribute("data") + "`n" | | } | | Write-Host "========当前天气情况======= | | 城市: $city | | 温度: $Temp | | 天气: $Condition | | $humidity | | $wind | | $Forecast" | | 输出的结果1: | | ========当前天气情况======= | | 城市: beijing | | 温度: 25 | | 天气: 雨 | | 湿度: 94% | | 风向: 东、风速:3 米/秒 | | 周三 22 - 29 可能有雨 | | 周四 24 - 31 雷阵雨 | | 周五 24 - 31 可能有暴风雨 | | 周六 22 - 28 可能有暴风雨 | | 输出的结果2: | | ========当前天气情况======= | | 城市: wuhan | | 温度: 32 | | 天气: 晴 | | 湿度: 62% | | 风向: 东南、风速:5 米/秒 | | 周三 26 - 35 可能有暴风雨 | | 周四 25 - 35 晴 | | 周五 26 - 35 可能有暴风雨 | | 周六 26 - 35 可能有暴风雨COPY |
http://hi.baidu.com/shrekzz/item/58ca56f01537a01dcf9f325d |