~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

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 exception 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