From a3cc7fa4957a85380693f19831b43fb752e94d18 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 18 Sep 2014 16:40:18 +0100 Subject: Added channel option for OCD message length perfection --- bladictionary.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'bladictionary.py') diff --git a/bladictionary.py b/bladictionary.py index 92fbea5..e19e8bd 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -7,7 +7,7 @@ import shlex import optparse from lxml import etree -VERSION = "2.0.11b" +VERSION = "2.0.12b" class Definition(object): #ID is relative to the word type, eg noun 1, noun 2, verb 1, verb 2, not to the entire list @@ -144,8 +144,10 @@ def parse_args(): args = shlex.split(sys.stdin.read()) parser = optparse.OptionParser( usage = "!define " ) - parser.add_option( "-v", "--version", action = "store_true" ) + parser.add_option( "-v", "--version", action = "store_true", help = "Print the version number" ) + parser.add_option( "-c", "--channel", action = "store", help = "The IRC channel of the request") options, args = parser.parse_args( args ) + types = ["n", "noun", "v", "verb", "adj", "adjective", "adv", "adverb"] dicts = ["wn", "wordnet", "oed"] @@ -163,7 +165,7 @@ def parse_args(): elif arg in dicts: word_dict = arg - return word, word_type, word_dict, options.version + return word, word_type, word_dict, options def parse_oed(word): types = ["n.", "—n.", "v.", "—v.", "adj.", "—adj.", "adv.", "—adv."] @@ -213,9 +215,9 @@ def parse_oed(word): def main(): - word, word_type, word_dict, version = parse_args() + word, word_type, word_dict, options = parse_args() - if version: + if options.version: print VERSION sys.exit( 0 ) @@ -235,6 +237,11 @@ def main(): num_more = 0 suppress_print = False + if options.channel: + max_length = 510 - 37 - len(options.channel) + else: + max_length = 460 + if items is None or len(items) == 0: print "No definition found for "+word return @@ -246,7 +253,7 @@ def main(): num_more+=1 else: definition = item.word_type + " " + str(item.id) + ": " + item.definition - if line_length + len(definition) > 458: + if line_length + len(definition) > max_length: suppress_print = True num_more+= 1 else: -- cgit v1.2.3