public static Weather GoogleWeather(string city) { const string baseUrl = @"https://www.google.com"; WebHelper connectionBase = new WebHelper(); UrlBuilder parameters = new UrlBuilder(string.Format(@"{0}/ig/api", baseUrl)); parameters.Add("hl", "zh-cn"); parameters.Add("weather", city); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(connectionBase.Get(parameters.ToString())); XmlNodeList nodeCity = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_information"); Weather.CityInfomaition cityInfo = new Weather.CityInfomaition( nodeCity.Item(0).SelectSingleNode("city").Attributes["data"].InnerText, nodeCity.Item(0).SelectSingleNode("postal_code").Attributes["data"].InnerText, nodeCity.Item(0).SelectSingleNode("latitude_e6").Attributes["data"].InnerText, nodeCity.Item(0).SelectSingleNode("longitude_e6").Attributes["data"].InnerText, nodeCity.Item(0).SelectSingleNode("unit_system").Attributes["data"].InnerText, Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("forecast_date").Attributes["data"].InnerText), Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("current_date_time").Attributes["data"].InnerText)); XmlNodeList nodeToday = xmlDocument.SelectNodes("xml_api_reply/weather/current_conditions"); Weather.TodayWeather today = new Weather.TodayWeather( Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText), Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText), nodeToday.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText, nodeToday.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText, nodeToday.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText, ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText)); XmlNodeList nodeList = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_conditions"); Weather.DayWeather tomorrow = new Weather.DayWeather( Convert.ToInt16(nodeList.Item(1).SelectSingleNode("high").Attributes["data"].InnerText), Convert.ToInt16(nodeList.Item(1).SelectSingleNode("low").Attributes["data"].InnerText), nodeList.Item(1).SelectSingleNode("condition").Attributes["data"].InnerText, ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText)); Weather.DayWeather third = new Weather.DayWeather( Convert.ToInt16(nodeList.Item(2).SelectSingleNode("high").Attributes["data"].InnerText), Convert.ToInt16(nodeList.Item(2).SelectSingleNode("low").Attributes["data"].InnerText), nodeList.Item(2).SelectSingleNode("condition").Attributes["data"].InnerText, ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText)); Weather.DayWeather fourth = new Weather.DayWeather( Convert.ToInt16(nodeList.Item(3).SelectSingleNode("high").Attributes["data"].InnerText), Convert.ToInt16(nodeList.Item(3).SelectSingleNode("low").Attributes["data"].InnerText), nodeList.Item(3).SelectSingleNode("condition").Attributes["data"].InnerText, ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText)); Weather weather = new Weather(cityInfo, today, tomorrow, third, fourth); return(weather); }
public string Get(UrlBuilder urlBuilder) { return(this.Get(urlBuilder.ToString())); }