Recent Changes List Macro
Examples: PersonalTelco
Download: RecentChangesList.py
Dependencies: feedparser
Also note this can be generalized to parse any feed in a short form.
1 # recent changes with diffs
2 Dependencies = ["time"]
3
4 from MoinMoin import util, wikiutil, config
5 from MoinMoin.Page import Page
6
7 class RSStoWiki:
8 def __init__(self, macro):
9 self.macro = macro
10 self.fmt = macro.formatter
11 url = "http://wiki.personaltelco.net/index.cgi/RecentChanges?action=rss_rc&unique=1&ddiffs=1"
12 import feedparser
13 self.f = feedparser.parse(url)
14 self.result = []
15
16 def get_link(self, link):
17 self.result.append(self.fmt.url(on=1, href=link) + \
self.fmt.icon('diff') + \
self.fmt.url(on=0))
18
19 def get_entry_header(self, title):
20 import re
21 tit = re.match('(.{30})', title)
22 if tit:
23 bigtits = tit.group(0)
24 tits = "<i>title too long</i>"
25 else:
26 tits = title
27 self.result.append(self.fmt.url(on=1, href='http://wiki.personaltelco.net/index.cgi/'+title) + \
self.fmt.rawHTML(" "+tits) + \
self.fmt.url(on=0) + \
self.fmt.rawHTML('<br>'))
28
29 def get_paragraph(self, text):
30 self.result.append(self.fmt.paragraph(on=1) + \
self.fmt.text(text) + \
self.fmt.paragraph(on=0))
31
32 def get_entry_body(self, body):
33 self.result.append(self.fmt.rawHTML(' <img src="http://wiki.personaltelco.net/images/comment2.png"> '))
34 self.result.append(self.fmt.text(body))
35 self.result.append(self.fmt.rawHTML('<br>'))
36
37 def get_description(self):
38 if not self.f.feed.has_key('description'):
39 return
40 self.get_paragraph(self.f.feed.description)
41
42 def get_entries(self):
43 self.f.entries = self.f.entries[:int(5)]
44 for entry in self.f.entries:
45 if entry.has_key('link'):
46 self.get_link(entry.link)
47 if entry.has_key('title'):
48 self.get_entry_header(entry.title)
49 if entry.has_key('description'):
50 self.get_entry_body(entry.description)
51
52
53 def get_output(self):
54 self.get_entries()
55 return ''.join(self.result)
56
57 def execute(macro, args):
58 rss = RSStoWiki(macro)
59 return rss.get_output()
