summaryrefslogtreecommitdiff
path: root/bladictionary.py
diff options
context:
space:
mode:
Diffstat (limited to 'bladictionary.py')
-rwxr-xr-xbladictionary.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/bladictionary.py b/bladictionary.py
index 42121a4..9fe1827 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
@@ -9,7 +9,7 @@ import sqlite3
import requests
from definition import Definition
-VERSION = "2.5.0"
+VERSION = "3.0"
def get_xml(word, word_dict):
api_url = "http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?dictId="+word_dict+"&word="+word
@@ -17,11 +17,11 @@ def get_xml(word, word_dict):
try:
xml = etree.parse(api_url)
except IOError:
- print "Error: Could not access the Dictionary service."
+ print ("Error: Could not access the Dictionary service.")
return
#Root element tag is WordDefinition, which is the same as the element which contains the definition
- #That's akward, so let's just
+ #That's akward, so let's just
for element in xml.iter("{http://services.aonaware.com/webservices/}Definitions"):
root = element
break;
@@ -95,7 +95,7 @@ def parse_xml(xml):
for part in line_parts:
extra_words = part.strip().split(" ")
for ant in extra_words:
- antonyms.append(syn.strip("{},] "))
+ antonyms.append(syn.strip("{},] "))
else:
definition += line_parts[0].strip() + " "
if len(line_parts) > 1:
@@ -117,7 +117,7 @@ def parse_xml(xml):
item = Definition(word, id, "wn", word_type, definition, [], synonyms, antonyms)
items.append(item)
-
+
return items
def parse_args():
@@ -173,7 +173,7 @@ def parse_args():
word = word.strip()
elif not options.version:
- print "You must specify a word to define"
+ print ("You must specify a word to define")
sys.exit(1)
return word, word_type, word_dict, page_num, options
@@ -214,11 +214,11 @@ def parse_oed(word):
definition = ""
word_type = ""
for part in line.split(" ")[word_len:]:
-
+
#If we've reached a word type, add the current data to the list
if part in types.keys():
#Don't add empty definitions
- if id > 0 and definition is not " " and definition:
+ if id > 0 and definition != " " and definition:
item = Definition(word, id, "oed", word_type, definition, [], [], [])
items.append(item)
definition = ""
@@ -228,14 +228,14 @@ def parse_oed(word):
elif part.isdigit() and prev_part is not None:
#Ignore anything before the first definition
- if part is not "1":
+ if part != "1":
item = Definition(word, id, "oed", word_type, definition, [], [], [])
items.append(item)
definition = ""
id = part
else:
definition += part.strip() + " "
-
+
prev_part = part
#Words with one definition don't have an id
@@ -268,14 +268,14 @@ def get_sql(word, dictionary = "wn"):
elif dictionary == "foldoc" or dictionary == "tech":
dict_id = 2
else:
- print "Invalid dictionary"
+ print ("Invalid dictionary")
sys.exit(1)
con = sqlite3.connect('dictionaries/wordnet.db');
con.row_factory = sqlite3.Row
with con:
-
+
cur = con.cursor()
cur.execute("SELECT * from definitions where word = ? and dictionary_id = ? ORDER BY type_id,sub_id;", [word, dict_id])
@@ -343,7 +343,7 @@ def main():
word, word_type, word_dict, page_num, options = parse_args()
if options.version:
- print VERSION
+ print (VERSION)
sys.exit( 0 )
if word_dict == "oed":
@@ -352,7 +352,7 @@ def main():
xml = get_xml(word, word_dict)
if xml is None:
- print "Error finding definitions for " + word
+ print ("Error finding definitions for " + word)
sys.exit( 1 )
items = parse_xml(xml)
@@ -374,7 +374,7 @@ def main():
items += urban_items
if items is None or len(items) == 0:
- print "No definitions found for "+word
+ print ("No definitions found for "+word)
sys.exit( 1 )
line_length = 0
@@ -392,7 +392,7 @@ def main():
types = ["n", "v", "adj", "adv", "tech", "urban"]
type_id = 0
- all_types = word_type is ""
+ all_types = word_type == ""
#Normally we try and display 1 of each type if no type is specified
#But if the word only has one type of definition, display all of them
@@ -411,7 +411,7 @@ def main():
found_type = False
cur_id = type_id
if item.id < page_num:
- if item.id is not 0:
+ if item.id != 0:
continue
elif item.id == 0 and page_num > 1:
continue
@@ -461,24 +461,24 @@ def main():
if line_length == 0:
#So truncate it
definition = definition[:max_length-3] + "..."
- print definition,
+ print (definition),
else:
num_more += 1
suppress_print = True
else:
- print definition,
+ print (definition),
line_length += len(definition) + 1
- #Once we've printed one word of any given type, move on to the next type
+ #Once we've printed one word of any given type, move on to the next type
if all_types:
type_id += 1
elif all_types and item.word_type is not word_type:
num_more+=1
-
+
if (suppress_print or all_types) and num_more > 0:
- print "(" + str(num_more) + " more)"
+ print ("(" + str(num_more) + " more)")
if __name__ == "__main__":
main()