From 383f2e37a0b7de605d4ab811b4024b11da4c8dac Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 16 Oct 2020 00:01:10 +0100 Subject: Add gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89c4590 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +definition.pyc +dictionaries/wordnet.db +__pycache__/ -- cgit v1.2.3 From 739442a34ca3d433b1abcefedbf25c58f8783b56 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 16 Oct 2020 00:01:19 +0100 Subject: Upgrade print syntax to python3 --- bladictionary.py | 36 ++++++++++++++++++------------------ 1 file 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() -- cgit v1.2.3 From b47464cb306ec152bec1500dfabeee503ebd0787 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 16 Oct 2020 00:19:17 +0100 Subject: Upgrade version number to 3.0 --- bladictionary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bladictionary.py b/bladictionary.py index 0611501..a7ca8ce 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -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 -- cgit v1.2.3 From ecf048b9c1fafffd8e6da1e666740c0311b50b7e Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 16 Oct 2020 00:24:00 +0100 Subject: Replace and when comparing stirngs and ints --- bladictionary.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bladictionary.py b/bladictionary.py index a7ca8ce..9fe1827 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -218,7 +218,7 @@ def parse_oed(word): #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,7 +228,7 @@ 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 = "" @@ -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 -- cgit v1.2.3