~ubuntu-branches/ubuntu/precise/gozerbot/precise

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/rsslist.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2008-06-02 19:26:39 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080602192639-3rn65nx4q1sgd6sy
Tags: 0.8.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# gozerbot/rsslist.py
2
 
#
3
 
#
4
 
 
5
 
""" create a list of rss data """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
from gozerbot.generic import handle_exception
10
 
import xml.dom.minidom
11
 
 
12
 
def gettext(nodelist):
13
 
    """ get text data from nodelist """
14
 
    result = ""
15
 
    for node in nodelist:
16
 
        if node.nodeType == node.TEXT_NODE or node.nodeType == \
17
 
node.CDATA_SECTION_NODE:
18
 
            stripped = node.data.strip()
19
 
            if stripped:
20
 
                result += stripped
21
 
    return result
22
 
 
23
 
def makersslist(xlist, nodes , d={}):
24
 
    """ recurse until txt is found """
25
 
    for i in nodes:
26
 
        if i.nodeType == i.ELEMENT_NODE:
27
 
            dd = d[i.nodeName] = {}
28
 
            makersslist(xlist, i.childNodes, dd)
29
 
            if dd:
30
 
                xlist.append(dd)
31
 
        txt = gettext(i.childNodes)
32
 
        if txt:
33
 
            d[i.nodeName] = txt
34
 
        
35
 
def rsslist(txt):
36
 
    """ create list of dictionaries with rss data """
37
 
    dom = xml.dom.minidom.parseString(txt)
38
 
    result = []
39
 
    makersslist(result, dom.childNodes)
40
 
    return result