diff options
Diffstat (limited to 'bladictionary.py')
| -rwxr-xr-x | bladictionary.py | 39 | 
1 files changed, 29 insertions, 10 deletions
diff --git a/bladictionary.py b/bladictionary.py index c3e135a..ab4acbc 100755 --- a/bladictionary.py +++ b/bladictionary.py @@ -326,19 +326,26 @@ def parse_foldoc(word, refer = False):  		#Foldoc definitions are split over multiple lines, so keep reading once we've found it  		else: -			 +			#Line with the specified word is followed by one blank line +			#Skip the first blank line, and then stop when any further blank lines are found  			if len(line) == 0:  				count_blank += 1  				if count_blank == 1:  					continue  				else:  					break + +			#If the line is just one string enclosed in {}s, then it means "see also", so look up that word +  			if line[0] == "{" and line[-1] == "}": -				parse_foldoc(line.strip("{} "), True) +				item = parse_foldoc(line.strip("{} "), True)[0] +				items.append(item) +				return items +  			for part in word_parts: -				definition += part.strip("{").replace("}", "") + " " +				definition += part.replace("{", "").replace("}", "") + " " -	if not found: +	if not found :  		return  	else:  		item = Definition(word, 0, "foldoc", "tech", definition, [], [], []) @@ -371,6 +378,7 @@ def main():  		if word_dict is None or word_dict == "":  			word_dict = "db"  			items = get_sql(word) +			items += parse_foldoc(word)  	if items is None or len(items) == 0:  		print "No definitions found for "+word @@ -404,8 +412,8 @@ def main():  			word_type = word_types[0]  			all_types = False -	for item in items: +	for item in items:  		#If no type is specified, we display one of each  		if all_types:  			found_type = False @@ -430,18 +438,29 @@ def main():  			if suppress_print:  				num_more+=1  			else: -				definition = item.word_type + " " + str(item.id) + ": " + item.definition -				if definition[-1] is not "." and definition[-1] is not " ": -					definition += "." +				if item.id > 0: +					definition = item.word_type + " " + str(item.id) + ": " + item.definition +				else: +					definition = item.word_type + ": " + item.definition +				if definition[-1] is not "." and definition[-1] is not " " and len(item.uses) == 0 : +					definition += ". " +				elif definition[-1] == "." : +					definition += " "  				#Print usage examples if they exist  				if len(item.uses) > 0: -					definition += "; \""+item.uses[0]['quote']+"\"" +					definition += "; \""+item.uses[0]['quote']+"\" "  				#Once we've reached the maximum length, stop printing any more  				if line_length + len(definition) +1 > max_length: +					#If we haven't printed anything so far, it's just one really long definition +					if line_length == 0: +						#So truncate it +						definition = definition[:max_length-3] + "..." +						print definition, +					else: +						num_more += 1  					suppress_print = True -					num_more+= 1  				else:  					print definition,  | 
