#!/usr/bin/env python

import urllib, xml.dom.minidom
from xml.dom.minidom import Node

def gettext(node):
    result = ''
    for child in node.childNodes:
        if child.nodeType == Node.TEXT_NODE:
            result += child.data
    return result

print 'Content-Type: text/html'
print

feeds = ['http://nyt.weblogs.com/rss.xml',
         'http://slashdot.org/slashdot.rss',
         'http://www.newsisfree.com/HPE/xml/feeds/96/696.xml',
         'http://www.newsisfree.com/HPE/xml/feeds/53/2353.xml']

for url in feeds:
    stream = urllib.urlopen(url)
    rdf = xml.dom.minidom.parse(stream)
    channel = rdf.getElementsByTagName('channel')[0]
    titlenode = channel.getElementsByTagName('title')[0]
    channelname = gettext(titlenode)
    print '<h1>%s</h1>' % channelname
    print
    for item in rdf.getElementsByTagName('item'):
        titlenode = item.getElementsByTagName('title')[0]
        linknode = item.getElementsByTagName('link')[0]
        title = gettext(titlenode)
        link = gettext(linknode)
        print '<li><a href="%s">%s</a>' % (link, title)
    print '</ul>'
    print

