Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added standard version location and udefine plugin
- Loading branch information
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include *.txt | ||
include hippybot/version.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BeautifulSoup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.1.0 |