please, work?
This commit is contained in:
parent
08b1e82f41
commit
c05b6b25c2
3 changed files with 17 additions and 9 deletions
|
@ -23,7 +23,7 @@ def mcwiki(inp):
|
||||||
if p.text_content():
|
if p.text_content():
|
||||||
summary = " ".join(p.text_content().splitlines())
|
summary = " ".join(p.text_content().splitlines())
|
||||||
summary = re.sub("\[\d+\]", "", summary)
|
summary = re.sub("\[\d+\]", "", summary)
|
||||||
summary = text.truncate_str(summary, 250)
|
summary = text.truncate_str(summary, 200)
|
||||||
return "%s :: \x02%s\x02" % (summary, url)
|
return "%s :: %s" % (summary, url)
|
||||||
|
|
||||||
return "Unknown Error."
|
return "Unknown Error."
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from util import hook, http, text
|
from util import hook, http, text, web
|
||||||
|
import re
|
||||||
|
|
||||||
base_url = 'http://www.urbandictionary.com/iphone/search/define'
|
base_url = 'http://www.urbandictionary.com/iphone/search/define'
|
||||||
|
|
||||||
|
@ -21,19 +22,26 @@ def urban(inp):
|
||||||
else:
|
else:
|
||||||
id = 1
|
id = 1
|
||||||
|
|
||||||
|
|
||||||
# fetch the definitions
|
# fetch the definitions
|
||||||
page = http.get_json(base_url, term=input, referer="http://m.urbandictionary.com")
|
page = http.get_json(base_url, term=input, referer="http://m.urbandictionary.com")
|
||||||
defs = page['list']
|
defs = page['list']
|
||||||
|
print page
|
||||||
|
|
||||||
if page['result_type'] == 'no_results':
|
if page['result_type'] == 'no_results':
|
||||||
return 'Not found.'
|
return 'Not found.'
|
||||||
|
|
||||||
# try getting the requested definition
|
# try getting the requested definition
|
||||||
try:
|
try:
|
||||||
output = u"[%i/%i] %s: %s" % \
|
definition = defs[id - 1]['definition'].replace('\r\n', ' ')
|
||||||
(id, len(defs), defs[id - 1]['word'],
|
definition = re.sub('\s+', ' ', definition).strip() # remove excess spaces
|
||||||
defs[id - 1]['definition'].replace('\r\n', ' '))
|
definition = text.truncate_str(definition, 200)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return 'Not found.'
|
return 'Not found.'
|
||||||
|
|
||||||
return text.truncate_str(output, 250)
|
url = defs[id - 1]['permalink']
|
||||||
|
|
||||||
|
output = u"[%i/%i] %s :: %s" % \
|
||||||
|
(id, len(defs), definition, url)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
|
@ -44,6 +44,6 @@ def wiki(inp):
|
||||||
|
|
||||||
desc = re.sub('\s+', ' ', desc).strip() # remove excess spaces
|
desc = re.sub('\s+', ' ', desc).strip() # remove excess spaces
|
||||||
|
|
||||||
desc = text.truncate_str(desc, 250)
|
desc = text.truncate_str(desc, 200)
|
||||||
|
|
||||||
return '%s -- %s' % (desc, http.quote(url, ':/'))
|
return '%s :: %s' % (desc, http.quote(url, ':/'))
|
||||||
|
|
Reference in a new issue