Skip to content

Commit

Permalink
[wikipedia] Bring module to 4.0 standards per issue #276
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed May 31, 2013
1 parent 854d511 commit 35473ff
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions willie/modules/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
http://willie.dftba.net
"""
import willie.web as web
from willie import web
from willie.module import NOLIMIT, commands, example
import json
import re

REDIRECT = re.compile(r'^REDIRECT (.*)')


def mw_search(server, query, num):
"""
Searches the specified MediaWiki server for the given query, and returns
Expand Down Expand Up @@ -44,21 +46,21 @@ def mw_snippet(server, query):
return snippet['extract']


def wikipedia(willie, trigger):
@commands('w', 'wiki', 'wik')
@example('.w San Francisco')
def wikipedia(bot, trigger):
query = trigger.group(2)
if not query:
willie.reply('What do you want me to look up?')
return willie.NOLIMIT
bot.reply('What do you want me to look up?')
return NOLIMIT
server = 'en.wikipedia.org'
query = mw_search(server, query, 1)
if not query:
willie.reply("I can't find any results for that.")
return willie.NOLIMIT
bot.reply("I can't find any results for that.")
return NOLIMIT
else:
query = query[0]
snippet = mw_snippet(server, query)

query = query.replace(' ', '_')
willie.say('"%s" - http://en.wikipedia.org/wiki/%s' % (snippet, query))
wikipedia.commands = ['w', 'wiki', 'wik']
wikipedia.example = '.w San Francisco'
bot.say('"%s" - http://en.wikipedia.org/wiki/%s' % (snippet, query))

0 comments on commit 35473ff

Please sign in to comment.