summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-09-18 14:58:58 +0100
committerJoe Robinson <joe@mumsnet.com>2014-09-18 14:58:58 +0100
commit778b673dc2e1d1249d303ef28893e4338699291b (patch)
tree79e49f9df2c47cd3f22cb9a7a52c86d9b7c35f9c
parentfb0cfe33d4125c80db0d7e5f0eeac5c86edbce24 (diff)
Limit lines length for IRC
-rwxr-xr-xbladictionary.py17
1 files 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)"