[Moin-devel] CVS: MoinMoin/macro RandomQuote.py,NONE,1.1
J?rgen Hermann
jhermann at users.sourceforge.net
Thu May 23 13:39:04 EDT 2002
Update of /cvsroot/moin/MoinMoin/macro
In directory usw-pr-cvs1:/tmp/cvs-serv25909/MoinMoin/macro
Added Files:
RandomQuote.py
Log Message:
RandomQuote macro
--- NEW FILE: RandomQuote.py ---
"""
MoinMoin - RandomQuote Macro
Copyright (c) 2002 by Jürgen Hermann <jh at web.de>
All rights reserved, see COPYING for details.
Originally written by Thomas Waldmann.
Selects a random quote from FortuneCookies or a given page.
Usage:
[[RandomQuote()]]
[[RandomQuote(WikiTips)]]
Comments:
It will look for list delimiters on the page in question.
It will ignore anything that is not in an "*" list.
$Id: RandomQuote.py,v 1.1 2002/05/23 20:38:03 jhermann Exp $
"""
import random
from MoinMoin.Page import Page
def execute(macro, args):
_ = macro.request.getText
pagename = args or 'FortuneCookies'
raw = Page(pagename).get_raw_body()
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
# !!! TODO: format the selected quote (pass through wiki parser)
quotes = raw.splitlines()
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
quotes = filter(None, [quote.rstrip() for quote in quotes])
quote = random.choice(quotes or [
macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % locals() +
macro.formatter.highlight(0)
])
return quote
More information about the Moin-devel
mailing list