from sets import Set
+from TagStrip import strip, strip_readable
class BaseFeed:
"""Base-class for all Feeds. Initializes needed Elements."""
MAX_HISTORY_ELEMENTS = 100
- def __init__(self, uri, autoupdate, stripper):
+ def __init__(self, uri, autoupdate):
# Set URI (used as Identifier)
self.uri = uri
# Set Autoupdate
self.autoupdate = autoupdate
- # Set Stripper
- self.stripper = stripper
-
# Initialize
self.title = uri.encode("UTF-8")
self.description = ""
# Try to read title, continue if none found
try:
- title = self.stripper.strip(item.getElementsByTagName("title")[0].childNodes[0].data)
+ title = strip(item.getElementsByTagName("title")[0].childNodes[0].data)
except:
continue
for current in item.getElementsByTagName("link"):
# Enclosure
if current.getAttribute("rel") == "enclosure":
- enclosure.append((
- current.getAttribute("href").encode("UTF-8"),
- current.getAttribute("type").encode("UTF-8")
- ))
+ href = current.getAttribute("href").encode("UTF-8")
+ type = current.getAttribute("type").encode("UTF-8")
+ enclosure.append((href, type))
# No Enclosure, assume its a link to the item
else:
link = current.getAttribute("href")
# Try to read summary, empty if none
try:
- summary = self.stripper.strip_readable(item.getElementsByTagName("summary")[0].childNodes[0].data)
+ summary = strip_readable(item.getElementsByTagName("summary")[0].childNodes[0].data)
except:
summary = ""
# Try to read title, continue if none found
try:
- title = self.stripper.strip(item.getElementsByTagName("title")[0].childNodes[0].data)
+ title = strip(item.getElementsByTagName("title")[0].childNodes[0].data)
except:
continue
# Try to read summary (description element), empty if none
try:
- summary = self.stripper.strip_readable(item.getElementsByTagName("description")[0].childNodes[0].data)
+ summary = strip_readable(item.getElementsByTagName("description")[0].childNodes[0].data)
except:
summary = ""
# Read out enclosures
for current in item.getElementsByTagName("enclosure"):
- enclosure.append((
- current.getAttribute("url").encode("UTF-8"),
- current.getAttribute("type").encode("UTF-8")
- ))
+ href = current.getAttribute("url").encode("UTF-8")
+ type = current.getAttribute("type").encode("UTF-8")
+ enclosure.append((href, type))
# Update Lists
new_items.append((
class UniversalFeed(BaseFeed, RSSFeed, AtomFeed):
"""Universal Feed which on first run determines its type and calls the correct parsing-functions"""
- def __init__(self, uri, autoupdate, stripper):
- BaseFeed.__init__(self, uri, autoupdate, stripper)
+ def __init__(self, uri, autoupdate):
+ BaseFeed.__init__(self, uri, autoupdate)
self.type = None
def gotDom(self, dom):
pass
else:
raise NotImplementedError, 'Unsupported Feed: %s' % dom.documentElement.localName
- self.title = self.stripper.strip(self.title).encode("UTF-8")
- self.description = self.stripper.strip_readable(self.description).encode("UTF-8")
+ self.title = strip(self.title).encode("UTF-8")
+ self.description = strip_readable(self.description).encode("UTF-8")
if self.type == "rss":
print "[SimpleRSS] type is rss"
return RSSFeed.gotDom(self, dom)