From 9d6a2b3992693a10b2cd3feb43d8e92dda718943 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Tue, 23 Sep 2014 16:12:16 +0100 Subject: Add urban dictionary definitions when no dictionary is specified --- bladictionary.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bladictionary.py b/bladictionary.py index a46137d..7a3112a 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -8,7 +8,7 @@ from lxml import etree import sqlite3 import requests -VERSION = "2.3.1" +VERSION = "2.3.2" class Definition(object): #ID is relative to the word type, eg noun 1, noun 2, verb 1, verb 2, not to the entire list @@ -466,10 +466,15 @@ def main(): if word_dict is None or word_dict == "": word_dict = "wn" items = get_sql(word) + foldoc_items = parse_foldoc(word) if foldoc_items is not None and len(foldoc_items) > 0: items += foldoc_items + urban_items = parse_urban(word) + if urban_items is not None and len(urban_items) > 0: + items += urban_items + if items is None or len(items) == 0: print "No definitions found for "+word sys.exit( 1 ) @@ -501,7 +506,6 @@ def main(): word_type = word_types[0] all_types = False - for item in items: #If no type is specified, we display one of each if all_types: @@ -514,6 +518,7 @@ def main(): continue #Definitions should be ordered by type, so loop through all the types until we find a match for cur_type in types[type_id:]: + if item.word_type == cur_type: word_type = cur_type type_id = cur_id @@ -523,7 +528,9 @@ def main(): #If there were no matches, stick with the current type for now if not found_type: - word_type = types[type_id] + + if type_id < len(types): + word_type = types[type_id] if word_type == item.word_type: #Keep track of how many we haven't printed -- cgit v1.2.3