Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / Visual Basic

Weather Forecast with Yahoo! Weather RSS Feed

Rate me:
Please Sign up or sign in to vote.
4.39/5 (20 votes)
13 Jul 2009CPOL2 min read 234.4K   3.4K   49  
A class based on the Yahoo! Weather RSS feed.
Imports Microsoft.VisualBasic
Imports System.Xml.Serialization
Public Class YahooWeatherForecast
    Public Enum conditionCode
        tornado = 0
        tropical_storm = 1
        hurricane = 2
        severe_thunderstorms = 3
        thunderstorms = 4
        mixed_rain_and_snow = 5
        mixed_rain_and_sleet = 6
        mixed_snow_and_sleet = 7
        freezing_drizzle = 8
        drizzle = 9
        freezing_rain = 10
        showers = 11
        showers_ = 12
        snow_flurries = 13
        light_snow_showers = 14
        blowing_snow = 15
        snow = 16
        hail = 17
        sleet = 18
        dust = 19
        foggy = 20
        haze = 21
        smoky = 22
        blustery = 23
        windy = 24
        cold = 25
        cloudy = 26
        mostly_cloudy_night = 27
        mostly_cloudy_day = 28
        partly_cloudy_night = 29
        partly_cloudy_day = 30
        clear_night = 31
        sunny = 32
        fair_night = 33
        fair_day = 34
        mixed_rain_and_hail = 35
        hot = 36
        isolated_thunderstorms = 37
        scattered_thunderstorms = 38
        scattered_thunderstorms_ = 39
        scattered_showers = 40
        heavy_snow = 41
        scattered_snow_showers = 42
        heavy_snow_ = 43
        partly_cloudy = 44
        thundershowers = 45
        snow_showers = 46
        isolated_thundershowers = 47
        not_available = 3200
    End Enum

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="p">US zip code or Location ID. </param>
    ''' <param name="U">Units for temperature.  f: Fahrenheit   c: Celsius</param>
    ''' <remarks></remarks>
    Sub New(ByVal p As String, ByVal U As String)
        Dim doc As New System.Xml.XmlDocument()
        Dim str As String = "http://weather.yahooapis.com/forecastrss?p=" & p & "&u=" & U
        Dim c As rssClass
        'Load data   
        doc.Load(str)
        str = doc.OuterXml


        'XmlSerializer could not Serialize XML with this Elements so i just replace them with Null String!
        str = str.Replace("yweather:", "")
        str = str.Replace("geo:", "")

        Dim memoryStream As New IO.MemoryStream()
        Dim d As New IO.StringReader(str)


        Dim xs As New XmlSerializer(GetType(rssClass))

        c = CType(xs.Deserialize(d), rssClass)

        rss = c

    End Sub

    Private _rss As rssClass
    <XmlElement()> _
    Public Property rss() As rssClass
        Get
            Return _rss
        End Get
        Set(ByVal value As rssClass)
            _rss = value
        End Set
    End Property
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions