private string LoadForecastData(CityWeather weather, string result) { result = result.Substring(27); var nNextForecastIndex = result.IndexOf("<div class=\"foreGlance\">"); string process; if (nNextForecastIndex > 0) process = result.Substring(0, nNextForecastIndex); else process = result; var nSubTitleIndexStart = process.IndexOf("<div class=\"titleSubtle\">"); var nSubTitleIndexEnd = process.IndexOf("</div>"); weather.When = process.Substring(nSubTitleIndexStart + 25, nSubTitleIndexEnd - nSubTitleIndexStart - 25); int nTempStartIndex; int nTempEndIndex; if (process.Contains("|")) { nTempStartIndex = process.IndexOf("<span class=\"b\">"); nTempEndIndex = process.IndexOf("</span>"); StringBuilder tempBuilder = new StringBuilder(); tempBuilder.Append(process.Substring(nTempStartIndex + 16, nTempEndIndex - nTempStartIndex - 16)); nTempStartIndex = process.IndexOf("|"); nTempEndIndex = process.IndexOf("°"); tempBuilder.Append(" | " + process.Substring(nTempStartIndex + 2, nTempEndIndex - nTempStartIndex - 2) + " C"); weather.Temperature = tempBuilder.ToString(); } else { if (process.Contains("<span class=\"b\">")) { nTempStartIndex = process.IndexOf("<span class=\"b\">"); nTempEndIndex = process.IndexOf("</span>"); weather.Temperature = process.Substring(nTempStartIndex + 16, nTempEndIndex - nTempStartIndex - 16) + " C"; } else { nTempStartIndex = process.IndexOf("</a>"); nTempEndIndex = process.IndexOf("°"); weather.Temperature = process.Substring(nTempStartIndex + 7, nTempEndIndex - nTempStartIndex - 7) + " C"; } } var nTitleIndexStart = process.IndexOf("<div class=\"foreCondition\">"); process = process.Substring(nTitleIndexStart); var nTitleIndexEnd = process.IndexOf("</div>"); weather.Condition = process.Substring(27, nTitleIndexEnd - 27); if (nNextForecastIndex > 0) result = result.Substring(nNextForecastIndex); return result; }
public void LoadData(string result) { m_currentCityWeather = new CityWeather(); m_currentCityWeather.When = "Now"; var nIndexCurrentCondition = result.IndexOf("<div id=\"curConds\">"); if (nIndexCurrentCondition > 0) { result = result.Substring(nIndexCurrentCondition); var nIndexScriptTag = result.IndexOf("<script type=\"text/javascript\">"); if (nIndexScriptTag > 0) { // get condition string result = result.Substring(0, nIndexScriptTag); var nNowConditionStart = result.IndexOf("<div id=\"curCond\">"); result = result.Substring(nNowConditionStart); var nNowConditionEnd = result.IndexOf("</div>"); m_currentCityWeather.Condition = result.Substring(18, nNowConditionEnd - 18); result = result.Substring(nNowConditionEnd); // get temperature var nNowTempStart = result.IndexOf("<span class=\"nobr\">"); result = result.Substring(nNowTempStart); var nNowTempEnd = result.IndexOf("</span>"); m_currentCityWeather.Temperature = result.Substring(35, nNowTempEnd - 35) + " C"; // get sunrise and sunset times var nSunriseTimeStart = result.IndexOf("<div id=\"sRise\">"); result = result.Substring(nSunriseTimeStart); var nSunriseTimeEnd = result.IndexOf("</span>"); m_currentCityWeather.SunRiseTime = result.Substring(32, nSunriseTimeEnd - 32) + " " + "AM"; var nSunsetTimeStart = result.IndexOf("<div id=\"sSet\">"); result = result.Substring(nSunsetTimeStart); var nSunsetTimeEnd = result.IndexOf("</span>"); m_currentCityWeather.SunSetTime = result.Substring(31, nSunsetTimeEnd - 31) + " " + "PM"; NotifyPropertyChanged("CurrentWeather"); // now time for future cast var hourZZIndex = result.IndexOf("<div id=\"hourZZ\">"); result = result.Substring(hourZZIndex + 17); var quickCastIndex = result.IndexOf("<div id=\"conds_quickcast\">"); result = result.Substring(0, quickCastIndex); m_forecastCityWeather1 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather1, result); NotifyPropertyChanged("ForecastWather1"); m_forecastCityWeather2 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather2, result); NotifyPropertyChanged("ForecastWather2"); m_forecastCityWeather3 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather3, result); NotifyPropertyChanged("ForecastWather3"); m_forecastCityWeather4 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather4, result); NotifyPropertyChanged("ForecastWather4"); m_forecastCityWeather5 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather5, result); NotifyPropertyChanged("ForecastWather5"); m_forecastCityWeather6 = new CityWeather(); result = LoadForecastData(m_forecastCityWeather6, result); NotifyPropertyChanged("ForecastWather6"); } } }