From 66acfaf24770bcaed0d1300c38ceb414c81452db Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 4 Oct 2017 21:34:40 +0100 Subject: Force UTF-8 output --- saucypy | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) mode change 100755 => 100644 saucypy diff --git a/saucypy b/saucypy old mode 100755 new mode 100644 index 3721ab4..fb1a5be --- a/saucypy +++ b/saucypy @@ -6,12 +6,12 @@ import optparse import shlex import sys -VERSION = "1.0.2" +VERSION = "1.0.3" ENTRIES_FILE = "saucypy.json" def find( key, entries ): - return difflib.get_close_matches( key, entries.keys(), cutoff = 0.3 ) + return difflib.get_close_matches( key, entries.keys(), 5, cutoff = 0.3 ) def parse_args(): args = sys.argv[1:] @@ -39,9 +39,14 @@ def main(): if options.add: key, value = options.add entries[key] = value - - json.dump( entries, open( ENTRIES_FILE, "w" ), indent = 4, sort_keys = True ) - print key + ": " + value + " added" + matches = find( key, entries ) + if len( matches ) > 1: + exact_match = filter( lambda x: x == key, matches ) + if exact_match: + print "There is already an item named " + key + else: + json.dump( entries, open( ENTRIES_FILE, "w" ), indent = 4, sort_keys = True ) + print key + ": " + value + " added" elif options.count: print "Entries: {0}".format( len( entries.keys() ) ) else: @@ -53,10 +58,10 @@ def main(): if len( matches ) > 1: exact_match = filter( lambda x: x == args[0], matches ) if exact_match: - print entries[exact_match[0]] + print entries[exact_match[0]].encode("utf-8") elif options.index is not None: try: - print entries[matches[options.index]] + print entries[matches[options.index]].encode("utf-8") except IndexError: print "Match index out of range." sys.exit( 1 ) -- cgit v1.2.3