1.1 --- a/README.txt Sun Mar 02 18:31:09 2008 +0100
1.2 +++ b/README.txt Sun Mar 02 18:31:45 2008 +0100
1.3 @@ -31,10 +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 -However, the FeedReader macro is preferable, at least with RSS 2.0 feeds since
1.10 -it parses the titles correctly.
1.11 +The FeedReader macro is used to fetch RSS 2.0 feeds and is preferable to the
1.12 +RSSReader macro available elsewhere since it parses the titles of feed entries
1.13 +correctly.
1.14
1.15 Administering Content
1.16 ---------------------
2.1 --- a/macros/RSSReader.py Sun Mar 02 18:31:09 2008 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,166 +0,0 @@
2.4 -# -*- coding: iso-8859-1 -*-
2.5 -"""
2.6 - Import a RSS Feed into MoinMoin
2.7 -
2.8 - @copyright: 2006 by Ian Wienand <ianw@ieee.org> (apparently assigned to the public domain)
2.9 - @copyright: 2008 by Paul Boddie <paul@boddie.org.uk>
2.10 - @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.11 -"""
2.12 -
2.13 -# Using this macro
2.14 -# [[RSSReader(url[,allow_html])]]
2.15 -# where
2.16 -# * url is the url of the RSS/ATOM feed to read
2.17 -# * allow_html is an optional argument if you trust the feed to put
2.18 -# the HTML directly into the page
2.19 -
2.20 -# CAUTION: this could be an attack vector, although feedparser should
2.21 -# strip most "bad" HTML.
2.22 -
2.23 -# this tells MoinMoin not to cache the page, as we don't know when it
2.24 -# changes.
2.25 -Dependencies = ["time"]
2.26 -
2.27 -from MoinMoin import util, wikiutil, config
2.28 -from MoinMoin.Page import Page
2.29 -
2.30 -class RSStoWiki:
2.31 - def __init__(self, macro, url, allow_html, compact_list):
2.32 - self.macro = macro
2.33 - self.fmt = macro.formatter
2.34 - self.url = url
2.35 - self.allow_html = allow_html
2.36 - self.compact_list = compact_list
2.37 - # in debian package python-feedparser
2.38 - import feedparser
2.39 - self.f = feedparser.parse(url)
2.40 - self.result = []
2.41 - if self.f.feed == {}:
2.42 - self.result.append (self.fmt.icon('info') + \
2.43 - self.fmt.strong(1) + \
2.44 - self.fmt.text(' Unable to retrieve feed %s' % url) + \
2.45 - self.fmt.strong(0))
2.46 - self.valid = False
2.47 - else:
2.48 - self.valid = True
2.49 -
2.50 -
2.51 - def get_title(self):
2.52 - if not self.f.feed.has_key('title'):
2.53 - return
2.54 - self.result.append(self.fmt.heading(on=1, depth=1) + \
2.55 - self.fmt.text(self.f.feed.title) + \
2.56 - self.fmt.heading(on=0, depth=1))
2.57 -
2.58 - def get_subtitle(self):
2.59 - if not self.f.feed.has_key('subtitle'):
2.60 - return
2.61 - self.result.append(self.fmt.heading(on=1, depth=2) + \
2.62 - self.fmt.text(self.f.feed.subtitle) + \
2.63 - self.fmt.heading(on=0, depth=2))
2.64 -
2.65 - def get_paragraph(self, text):
2.66 - self.result.append(self.fmt.paragraph(on=1) + \
2.67 - self.fmt.text(text) + \
2.68 - self.fmt.paragraph(on=0))
2.69 -
2.70 - def get_link(self, link):
2.71 - self.result.append(self.fmt.url(on=1, href=link) + \
2.72 - self.fmt.icon('www') + \
2.73 - self.fmt.text(" "+link) + \
2.74 - self.fmt.url(on=0))
2.75 -
2.76 - def get_feedlink(self):
2.77 - if not self.f.feed.has_key('link'):
2.78 - return
2.79 - self.get_link(self.f.feed.link)
2.80 -
2.81 - def get_description(self):
2.82 - if not self.f.feed.has_key('description'):
2.83 - return
2.84 - self.get_paragraph(self.f.feed.description)
2.85 -
2.86 - def get_rule(self):
2.87 - self.result.append(self.fmt.rule(size=1))
2.88 -
2.89 - def get_entry_header(self, title):
2.90 - self.result.append(self.fmt.heading(on=1, depth=3) + \
2.91 - self.fmt.text(title) + \
2.92 - self.fmt.heading(on=0, depth=3))
2.93 -
2.94 - def get_entry_body(self, body):
2.95 - self.result.append(self.fmt.paragraph(on=1))
2.96 - if (self.allow_html):
2.97 - self.result.append(self.fmt.rawHTML(body))
2.98 - else:
2.99 - self.result.append(self.fmt.text(body))
2.100 - self.result.append(self.fmt.paragraph(on=0))
2.101 -
2.102 - def get_entries(self):
2.103 - for entry in self.f.entries:
2.104 - if entry.has_key('title'):
2.105 - self.get_entry_header(entry.title)
2.106 - if entry.has_key('updated'):
2.107 - self.get_paragraph(entry.updated)
2.108 - if entry.has_key('description'):
2.109 - self.get_entry_body(entry.description)
2.110 - if entry.has_key('link'):
2.111 - self.get_link(entry.link)
2.112 -
2.113 - def get_compact_title(self):
2.114 - if not self.f.feed.has_key('title') or not self.f.feed.has_key('link'):
2.115 - return
2.116 - self.result.append(self.fmt.url(on=1, href=self.f.feed.link) + \
2.117 - self.fmt.text(self.f.feed.title) + \
2.118 - self.fmt.url(on=0) + \
2.119 - self.fmt.text(" ") + \
2.120 - self.fmt.url(on=1, href=self.url) + \
2.121 - self.fmt.icon('rss') + \
2.122 - self.fmt.url(on=0))
2.123 -
2.124 - def get_compact_entry(self, entry):
2.125 - if entry.has_key('link') and entry.has_key('title'):
2.126 - self.result.append(self.fmt.listitem(on=1))
2.127 - #self.result.append(self.fmt.paragraph(on=1))
2.128 - self.result.append(self.fmt.url(on=1, href=entry.link) + \
2.129 - self.fmt.icon('www') + \
2.130 - self.fmt.text(" "+entry.title) + \
2.131 - self.fmt.url(on=0))
2.132 - #self.result.append(self.fmt.paragraph(on=0))
2.133 - self.result.append(self.fmt.listitem(on=0))
2.134 -
2.135 - def get_compact_entries(self):
2.136 - self.result.append(self.fmt.bullet_list(on=1))
2.137 - for entry in self.f.entries:
2.138 - self.get_compact_entry(entry)
2.139 - self.result.append(self.fmt.bullet_list(on=0))
2.140 -
2.141 - def get_output(self):
2.142 - if self.valid:
2.143 - if self.compact_list:
2.144 - self.get_compact_title()
2.145 - self.get_compact_entries()
2.146 - else:
2.147 - self.get_title()
2.148 - self.get_subtitle()
2.149 - self.get_description()
2.150 - self.get_feedlink()
2.151 - self.get_rule()
2.152 - self.get_entries()
2.153 - self.get_rule()
2.154 - return ''.join(self.result)
2.155 -
2.156 -def execute(macro, args):
2.157 - macro_args = args.split(",")
2.158 - allow_html = False
2.159 - compact_list = False
2.160 - try:
2.161 - if macro_args[1].strip() == "allow_html":
2.162 - allow_html = True
2.163 - if macro_args[1].strip() == "compact_list":
2.164 - compact_list = True
2.165 - except:
2.166 - pass
2.167 -
2.168 - rss = RSStoWiki(macro, macro_args[0], allow_html, compact_list)
2.169 - return rss.get_output()