From 8783cb3f0d6e47545542da2641a24035f001d85e Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 24 Apr 2012 00:07:17 +1200 Subject: [PATCH] Split .urban from dictionary.py --- plugins/dictionary.py | 39 --------------------------------------- plugins/urban.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 39 deletions(-) create mode 100755 plugins/urban.py diff --git a/plugins/dictionary.py b/plugins/dictionary.py index 934a8b8..2562ceb 100755 --- a/plugins/dictionary.py +++ b/plugins/dictionary.py @@ -4,45 +4,6 @@ from util import hook from util import http -@hook.command('u') -@hook.command -def urban(inp): - ".urban [id] -- Looks up on urbandictionary.com." - - # set a default definition number - id = 1 - - # clean and split the input - input = inp.lower().strip() - parts = input.split() - - # if the last word is a number, set the ID to that number - if parts[-1].isdigit(): - id = int(parts[-1]) - del parts[-1] - input = " ".join(parts) - - url = 'http://www.urbandictionary.com/iphone/search/define' - page = http.get_json(url, term=input) - defs = page['list'] - - if page['result_type'] == 'no_results': - return 'Not found.' - - # try getting the requested definition - try: - out = "[%s/%s] %s: %s" % \ - (str(id), str(len(defs)), defs[id - 1]['word'], - defs[id - 1]['definition']) - except IndexError: - return 'Not found.' - - if len(out) > 400: - out = out[:out.rfind(' ', 0, 400)] + '...' - - return out - - @hook.command('dictionary') @hook.command def define(inp): diff --git a/plugins/urban.py b/plugins/urban.py new file mode 100755 index 0000000..4367d34 --- /dev/null +++ b/plugins/urban.py @@ -0,0 +1,43 @@ +# Plugin by Lukeroge +from util import hook, http + + +@hook.command('u') +@hook.command +def urban(inp): + ".urban [id] -- Looks up on urbandictionary.com." + + # set a default definition number + id = 1 + + # clean and split the input + input = inp.lower().strip() + parts = input.split() + + # if the last word is a number, set the ID to that number + if parts[-1].isdigit(): + id = int(parts[-1]) + # remove the ID from the input string + del parts[-1] + input = " ".join(parts) + + # fetch the definitions + url = 'http://www.urbandictionary.com/iphone/search/define' + page = http.get_json(url, term=input) + defs = page['list'] + + if page['result_type'] == 'no_results': + return 'Not found.' + + # try getting the requested definition + try: + out = "[%i/%i] %s: %s" % \ + (id, len(defs), defs[id - 1]['word'], + defs[id - 1]['definition']) + except IndexError: + return 'Not found.' + + if len(out) > 400: + out = out[:out.rfind(' ', 0, 400)] + '...' + + return out