summaryrefslogtreecommitdiff
path: root/bladictionary.py
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-10-16 00:01:19 +0100
committerFbenas <philbeansburton@gmail.com>2020-10-16 00:01:19 +0100
commit739442a34ca3d433b1abcefedbf25c58f8783b56 (patch)
tree7f72a67a8c6590c923a6817fef22074e17e863f4 /bladictionary.py
parent383f2e37a0b7de605d4ab811b4024b11da4c8dac (diff)
Upgrade print syntax to python3
Diffstat (limited to 'bladictionary.py')
-rwxr-xr-xbladictionary.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/bladictionary.py b/bladictionary.py
index 42121a4..0611501 100755
--- a/bladictionary.py
+++ b/bladictionary.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
@@ -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,7 +214,7 @@ 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
@@ -235,7 +235,7 @@ def parse_oed(word):
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
@@ -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()