diff options
author | Joe Robinson <joe@lc8n.com> | 2017-10-04 21:34:40 +0100 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2017-10-04 21:34:40 +0100 |
commit | 66acfaf24770bcaed0d1300c38ceb414c81452db (patch) | |
tree | f3466a2786829acf6908d26287629864d06a7ac7 | |
parent | 20970036076acb81ebe3d31cdb6d38609610cc0e (diff) |
Force UTF-8 output
-rw-r--r--[-rwxr-xr-x] | saucypy | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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 ) |