示例#1
0
    def suck_feed(self):
        #Indexes RSS data by item URL
        tc = TrackingChannel()

        #Returns the RSSParser instance used, which can usually be ignored
        print "Fetching ", self.url, " ..."
        tc.parse(self.url)

        RSS10_TITLE = (ns.rss10, 'title')
        RSS10_DESC = (ns.rss10, 'description')

        self.list = list()

        items = tc.listItems()
        for item in items:
            url = item[0].replace("ol", "dl")
            print url
            self.list.append(url)
def getRSSData(stationCode=10326):
    """acquires rss data from wunderground and parses it for current weather conditions at stationCode"""
    """stationCode for Graz: 11240"""

    from RSS import ns, CollectionChannel, TrackingChannel

    #Create a tracking channel, which is a data structure that
    #Indexes RSS data by item URL
    tc = TrackingChannel()

    #Returns the RSSParser instance used, which can usually be ignored
    tc.parse(
        "http://rss.wunderground.com/auto/rss_full/global/stations/%s.xml" %
        stationCode)

    RSS10_TITLE = (ns.rss10, 'title')
    RSS10_DESC = (ns.rss10, 'description')

    #You can also use tc.keys()
    items = tc.listItems()

    item = items[0]
    #Each item is a (url, order_index) tuple
    url = item[0]

    #Get all the data for the item as a Python dictionary
    item_data = tc.getItem(item)

    title = item_data.get(RSS10_TITLE, "(none)")
    description = item_data.get(RSS10_DESC, "(none)")

    #print "Title:", title
    #print "Description:", item_data.get(RSS10_DESC, "(none)")

    if title.find("Current Conditions") >= 0:
        valueDict = parseCurrentCond(description)

    return valueDict