How can I get hourly weather forecast in VB.net? -
i've seen questions similar on here, none of them seem me. don't care api used, google, yahoo!, weather channel, or other. i've got code high , low of current day, based on location given user, can't seem hourly predictions temperature or weather condition, i'm looking for. don't care wind speeds, humidity, or "feels like" temperature, though i'll add them if can figure out how to. i'm trying data here. (www.weather.com/...)
i'm pretty new parsing xml may part of problem, too. in advance help. appreciate it.
i have might enjoy:
<runtime.compilerservices.extension()> module weather public structure weatherinfo_forecast dim dayofweek string dim low double dim high double dim icon string end structure public structure weatherinfo_wind dim direction string dim speed double dim unit string end structure public structure weatherinfo_typed dim failed boolean dim errormessage exception dim location string dim forcast_date datetime dim checked_time_date datetime dim humidity double dim highf double dim lowf double dim highc double dim lowc double dim currenttempc double dim currenttempf double dim predicted_icon string dim current_icon string dim current_condition string dim predicted_condition ienumerable(of weatherinfo_forecast) dim wind_condition weatherinfo_wind dim day string end structure <runtime.compilerservices.extension()> _ public function toc(byval f double) double return ((f - 32) / 9) * 5 end function <runtime.compilerservices.extension()> _ public function tryparseasdouble(byval s string) double dim rv double if double.tryparse(s, rv) = false rv = double.nan return rv end function <runtime.compilerservices.extension()> _ public function tryparseasdate(byval s string) datetime dim rv datetime if datetime.tryparse(s, rv) = false rv = nothing return rv end function private function parsehumidity(byval s string) double if not s nothing dim humregex new system.text.regularexpressions.regex("humidity: (?<value>\d+)\w*\%") dim m = humregex.match(s) if m.length = 0 return double.nan return double.parse(m.groups("value").value) end if end function private function parsewind(byval s string) weatherinfo_wind dim rv new weatherinfo_wind if not s nothing dim humregex new system.text.regularexpressions.regex("wind\:\s+(?<direction>[newsnews]{1,2})\s+at\s+(?<speed>(?<value>\d+)\s(?<units>\w+)){1}") dim m = humregex.match(s) rv.speed = double.nan if m.length = 0 return rv rv .direction = m.groups("direction").value if double.tryparse(m.groups("value").value, .speed) = false .speed = double.nan .unit = m.groups("units").value end end if return rv end function <debuggerhidden()> public function grab_weather(byval location string) weatherinfo_typed dim grabweather new weatherinfo_typed grabweather .failed = true try dim xml xdocument = xdocument.load("http://www.google.com/ig/api?weather=" & location) dim xp = xml.<problem_cause> if xp.any return grabweather .location = xml...<city>.@data .forcast_date = xml...<forecast_date>.@data.tryparseasdate .checked_time_date = xml...<current_date_time>.@data.tryparseasdate .humidity = parsehumidity(xml...<humidity>.@data) .highf = xml...<high>.@data.tryparseasdouble .lowf = xml...<low>.@data.tryparseasdouble .highc = grabweather.highf.toc .lowc = grabweather.highc.toc .currenttempc = xml...<temp_c>.@data.tryparseasdouble .currenttempf = xml...<temp_f>.@data.tryparseasdouble '.current_icon = "http://www.google.com" & xml...<icon>.@data '.predicted_icon = "http://www.google.com" & xml...<high>.@data .current_condition = xml...<condition>.@data .predicted_condition = f in xml...<forecast_conditions> _ select new weatherinfo_forecast { _ .dayofweek = f.<day_of_week>.value, _ .high = f.<high>.@data.tryparseasdouble, _ .low = f.<low>.@data.tryparseasdouble} '.icon = "http://www.google.com" & f.<icon>.@data} .wind_condition = parsewind(xml...<wind_condition>.@data) .day = xml...<day_of_week>.@data .failed = false return grabweather catch ex exception .errormessage = ex return grabweather end try end end function end module
Comments
Post a Comment