1.1 --- a/README.txt Fri Feb 15 01:17:20 2008 +0100
1.2 +++ b/README.txt Sun Feb 24 21:06:46 2008 +0100
1.3 @@ -31,6 +31,9 @@
1.4
1.5 sudo ./instmacros .../ep2008
1.6
1.7 +The RSSReader macro was found on the MoinMoin macro market and requires the
1.8 +feedparser module (provided by the python-feedparser package on Debian/Ubuntu).
1.9 +
1.10 Administering Content
1.11 ---------------------
1.12
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/macros/RSSReader.py Sun Feb 24 21:06:46 2008 +0100
2.3 @@ -0,0 +1,125 @@
2.4 +# Import a RSS Feed into MoinMoin
2.5 +# Ian Wienand <ianw@ieee.org>
2.6 +# (C) 2006 - Public Domain
2.7 +
2.8 +# Using this macro
2.9 +# [[RSSReader(url[,allow_html])]]
2.10 +# where
2.11 +# * url is the url of the RSS/ATOM feed to read
2.12 +# * allow_html is an optional argument if you trust the feed to put
2.13 +# the HTML directly into the page
2.14 +
2.15 +# CAUTION: this could be an attack vector, although feedparser should
2.16 +# strip most "bad" HTML.
2.17 +
2.18 +# this tells MoinMoin not to cache the page, as we don't know when it
2.19 +# changes.
2.20 +Dependencies = ["time"]
2.21 +
2.22 +from MoinMoin import util, wikiutil, config
2.23 +from MoinMoin.Page import Page
2.24 +
2.25 +class RSStoWiki:
2.26 + def __init__(self, macro, url, allow_html):
2.27 + self.macro = macro
2.28 + self.fmt = macro.formatter
2.29 + self.allow_html = allow_html
2.30 + # in debian package python-feedparser
2.31 + import feedparser
2.32 + self.f = feedparser.parse(url)
2.33 + self.result = []
2.34 + if self.f.feed == {}:
2.35 + self.result.append (self.fmt.icon('info') + \
2.36 + self.fmt.strong(1) + \
2.37 + self.fmt.text(' Unable to retreive feed %s' % url) + \
2.38 + self.fmt.strong(0))
2.39 + self.valid = False
2.40 + else:
2.41 + self.valid = True
2.42 +
2.43 +
2.44 + def get_title(self):
2.45 + if not self.f.feed.has_key('title'):
2.46 + return
2.47 + self.result.append(self.fmt.heading(on=1, depth=1) + \
2.48 + self.fmt.text(self.f.feed.title) + \
2.49 + self.fmt.heading(on=0, depth=1))
2.50 +
2.51 + def get_subtitle(self):
2.52 + if not self.f.feed.has_key('subtitle'):
2.53 + return
2.54 + self.result.append(self.fmt.heading(on=1, depth=2) + \
2.55 + self.fmt.text(self.f.feed.subtitle) + \
2.56 + self.fmt.heading(on=0, depth=2))
2.57 +
2.58 + def get_paragraph(self, text):
2.59 + self.result.append(self.fmt.paragraph(on=1) + \
2.60 + self.fmt.text(text) + \
2.61 + self.fmt.paragraph(on=0))
2.62 +
2.63 + def get_link(self, link):
2.64 + self.result.append(self.fmt.url(on=1, href=link) + \
2.65 + self.fmt.icon('www') + \
2.66 + self.fmt.text(" "+link) + \
2.67 + self.fmt.url(on=0))
2.68 +
2.69 + def get_feedlink(self):
2.70 + if not self.f.feed.has_key('link'):
2.71 + return
2.72 + self.get_link(self.f.feed.link)
2.73 +
2.74 + def get_description(self):
2.75 + if not self.f.feed.has_key('description'):
2.76 + return
2.77 + self.get_paragraph(self.f.feed.description)
2.78 +
2.79 + def get_rule(self):
2.80 + self.result.append(self.fmt.rule(size=1))
2.81 +
2.82 + def get_entry_header(self, title):
2.83 + self.result.append(self.fmt.heading(on=1, depth=3) + \
2.84 + self.fmt.text(title) + \
2.85 + self.fmt.heading(on=0, depth=3))
2.86 +
2.87 + def get_entry_body(self, body):
2.88 + self.result.append(self.fmt.paragraph(on=1))
2.89 + if (self.allow_html):
2.90 + self.result.append(self.fmt.rawHTML(body))
2.91 + else:
2.92 + self.result.append(self.fmt.text(body))
2.93 + self.result.append(self.fmt.paragraph(on=0))
2.94 +
2.95 + def get_entries(self):
2.96 + for entry in self.f.entries:
2.97 + if entry.has_key('title'):
2.98 + self.get_entry_header(entry.title)
2.99 + if entry.has_key('updated'):
2.100 + self.get_paragraph(entry.updated)
2.101 + if entry.has_key('description'):
2.102 + self.get_entry_body(entry.description)
2.103 + if entry.has_key('link'):
2.104 + self.get_link(entry.link)
2.105 +
2.106 + def get_output(self):
2.107 + if self.valid:
2.108 + self.get_title()
2.109 + self.get_subtitle()
2.110 + self.get_description()
2.111 + self.get_feedlink()
2.112 + self.get_rule()
2.113 + self.get_entries()
2.114 + self.get_rule()
2.115 + return ''.join(self.result)
2.116 +
2.117 +def execute(macro, args):
2.118 + macro_args = args.split(",")
2.119 + try:
2.120 + if macro_args[1].strip() == "allow_html":
2.121 + allow_html = True
2.122 + else:
2.123 + allow_html = False
2.124 + except:
2.125 + allow_html = False
2.126 +
2.127 + rss = RSStoWiki(macro, macro_args[0], allow_html)
2.128 + return rss.get_output()