1.1 --- a/macros/RSSReader.py Sun Feb 24 21:06:46 2008 +0100
1.2 +++ b/macros/RSSReader.py Tue Feb 26 02:13:09 2008 +0100
1.3 @@ -1,6 +1,11 @@
1.4 -# Import a RSS Feed into MoinMoin
1.5 -# Ian Wienand <ianw@ieee.org>
1.6 -# (C) 2006 - Public Domain
1.7 +# -*- coding: iso-8859-1 -*-
1.8 +"""
1.9 + Import a RSS Feed into MoinMoin
1.10 +
1.11 + @copyright: 2006 by Ian Wienand <ianw@ieee.org> (apparently assigned to the public domain)
1.12 + @copyright: 2008 by Paul Boddie <paul@boddie.org.uk>
1.13 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.14 +"""
1.15
1.16 # Using this macro
1.17 # [[RSSReader(url[,allow_html])]]
1.18 @@ -20,10 +25,12 @@
1.19 from MoinMoin.Page import Page
1.20
1.21 class RSStoWiki:
1.22 - def __init__(self, macro, url, allow_html):
1.23 + def __init__(self, macro, url, allow_html, compact_list):
1.24 self.macro = macro
1.25 self.fmt = macro.formatter
1.26 + self.url = url
1.27 self.allow_html = allow_html
1.28 + self.compact_list = compact_list
1.29 # in debian package python-feedparser
1.30 import feedparser
1.31 self.f = feedparser.parse(url)
1.32 @@ -31,7 +38,7 @@
1.33 if self.f.feed == {}:
1.34 self.result.append (self.fmt.icon('info') + \
1.35 self.fmt.strong(1) + \
1.36 - self.fmt.text(' Unable to retreive feed %s' % url) + \
1.37 + self.fmt.text(' Unable to retrieve feed %s' % url) + \
1.38 self.fmt.strong(0))
1.39 self.valid = False
1.40 else:
1.41 @@ -100,26 +107,60 @@
1.42 if entry.has_key('link'):
1.43 self.get_link(entry.link)
1.44
1.45 + def get_compact_title(self):
1.46 + if not self.f.feed.has_key('title') or not self.f.feed.has_key('link'):
1.47 + return
1.48 + self.result.append(self.fmt.url(on=1, href=self.f.feed.link) + \
1.49 + self.fmt.text(self.f.feed.title) + \
1.50 + self.fmt.url(on=0) + \
1.51 + self.fmt.text(" ") + \
1.52 + self.fmt.url(on=1, href=self.url) + \
1.53 + self.fmt.icon('rss') + \
1.54 + self.fmt.url(on=0))
1.55 +
1.56 + def get_compact_entry(self, entry):
1.57 + if entry.has_key('link') and entry.has_key('title'):
1.58 + self.result.append(self.fmt.listitem(on=1))
1.59 + #self.result.append(self.fmt.paragraph(on=1))
1.60 + self.result.append(self.fmt.url(on=1, href=entry.link) + \
1.61 + self.fmt.icon('www') + \
1.62 + self.fmt.text(" "+entry.title) + \
1.63 + self.fmt.url(on=0))
1.64 + #self.result.append(self.fmt.paragraph(on=0))
1.65 + self.result.append(self.fmt.listitem(on=0))
1.66 +
1.67 + def get_compact_entries(self):
1.68 + self.result.append(self.fmt.bullet_list(on=1))
1.69 + for entry in self.f.entries:
1.70 + self.get_compact_entry(entry)
1.71 + self.result.append(self.fmt.bullet_list(on=0))
1.72 +
1.73 def get_output(self):
1.74 if self.valid:
1.75 - self.get_title()
1.76 - self.get_subtitle()
1.77 - self.get_description()
1.78 - self.get_feedlink()
1.79 - self.get_rule()
1.80 - self.get_entries()
1.81 - self.get_rule()
1.82 + if self.compact_list:
1.83 + self.get_compact_title()
1.84 + self.get_compact_entries()
1.85 + else:
1.86 + self.get_title()
1.87 + self.get_subtitle()
1.88 + self.get_description()
1.89 + self.get_feedlink()
1.90 + self.get_rule()
1.91 + self.get_entries()
1.92 + self.get_rule()
1.93 return ''.join(self.result)
1.94
1.95 def execute(macro, args):
1.96 macro_args = args.split(",")
1.97 + allow_html = False
1.98 + compact_list = False
1.99 try:
1.100 if macro_args[1].strip() == "allow_html":
1.101 allow_html = True
1.102 - else:
1.103 - allow_html = False
1.104 + if macro_args[1].strip() == "compact_list":
1.105 + compact_list = True
1.106 except:
1.107 - allow_html = False
1.108 + pass
1.109
1.110 - rss = RSStoWiki(macro, macro_args[0], allow_html)
1.111 + rss = RSStoWiki(macro, macro_args[0], allow_html, compact_list)
1.112 return rss.get_output()