Skip to content

Commit

Permalink
Added standard version location and udefine plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
1stvamp committed Sep 26, 2011
1 parent 969c852 commit 51a8c01
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1 +1,2 @@
include *.txt
include hippybot/version.txt
1 change: 1 addition & 0 deletions extras_requirements.txt
@@ -0,0 +1 @@
BeautifulSoup
35 changes: 35 additions & 0 deletions hippybot/plugins/udefine.py
@@ -0,0 +1,35 @@
import requests
from BeautifulSoup import BeautifulSoup as Soup
from hippybot.hipchat import HipChatApi
from hippybot.decorators import directcmd

UD_SEARCH_URI = "http://www.urbandictionary.com/iphone/search/define"

class Plugin(object):
"""Plugin to lookup definitions from urbandictionary.com
"""
global_commands = ('udefine',)

@directcmd
def udefine(self, mess, args):
json = requests.get(UD_SEARCH_URI, params={'term': args})
results = []
if json:
json = json.replace(r'\r', '')
data = loads(json)
if data.get('result_type', '') != 'no_results' and \
data.has_key('list') and len(data['list']) > 0:
for datum in data['list']:
if datum.get('word', '') == term:
# Sanitization
definition = datum['definition']
re.sub(r'\s', ' ', definition)
definition = u''.join(Soup(definition).findAll(text=True))
definition = unicode(Soup(definition, convertEntities=Soup.HTML_ENTITIES))
results.append(definition)
if results:
reply = u"\n".join(results)
return reply
else:
return u'No matches found for "%s"' % (args,)

1 change: 1 addition & 0 deletions hippybot/version.txt
@@ -0,0 +1 @@
1.1.0

0 comments on commit 51a8c01

Please sign in to comment.