From 778b673dc2e1d1249d303ef28893e4338699291b Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 18 Sep 2014 14:58:58 +0100 Subject: Limit lines length for IRC --- bladictionary.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bladictionary.py b/bladictionary.py index 5d7f0bf..f7fcaec 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -207,6 +207,8 @@ def main(): if word_dict == "oed": items = parse_oed(word) else: + if word_dict == "" or word_dict is None: + word_dict = "wn" xml = get_xml(word, word_dict) if xml is None: @@ -214,21 +216,24 @@ def main(): items = parse_xml(xml) - num_printed = 0 + line_length = 0 num_more = 0 suppress_print = False for item in items: - if num_printed == 3: - suppress_print = True - if word_type is "" or word_type == item.word_type: if suppress_print: num_more+=1 else: - print item.word_type + " " + item.id + ": " + item.definition, - num_printed+=1 + definition = item.word_type + " " + item.id + ": " + item.definition + if line_length + len(definition) > 455: + suppress_print = True + num_more+= 1 + else: + print definition, + + line_length += len(definition) if suppress_print: print "(" + str(num_more) + " more)" -- cgit v1.2.3