Fixed formatting.

This commit is contained in:
Fletcher Boyd 2013-09-04 18:30:04 +08:00
parent 146ae3c279
commit 4069dd21a3
89 changed files with 615 additions and 496 deletions

View file

@ -1,4 +1,4 @@
from util import hook, http, text, web
from util import hook, http, text
import re
base_url = 'http://www.urbandictionary.com/iphone/search/define'
@ -7,7 +7,7 @@ base_url = 'http://www.urbandictionary.com/iphone/search/define'
@hook.command('u')
@hook.command
def urban(inp):
"urban <phrase> [id] -- Looks up <phrase> on urbandictionary.com."
"""urban <phrase> [id] -- Looks up <phrase> on urbandictionary.com."""
# clean and split the input
input = inp.lower().strip()
@ -22,7 +22,6 @@ def urban(inp):
else:
id = 1
# fetch the definitions
page = http.get_json(base_url, term=input, referer="http://m.urbandictionary.com")
defs = page['list']
@ -35,13 +34,13 @@ def urban(inp):
try:
definition = defs[id - 1]['definition'].replace('\r\n', ' ')
definition = re.sub('\s+', ' ', definition).strip() # remove excess spaces
definition = text.truncate_str(definition, 200)
definition = text.truncate_str(definition, 200)
except IndexError:
return 'Not found.'
url = defs[id - 1]['permalink']
output = u"[%i/%i] %s :: %s" % \
(id, len(defs), definition, url)
(id, len(defs), definition, url)
return output