summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2017-10-04 21:34:40 +0100
committerJoe Robinson <joe@lc8n.com>2017-10-04 21:34:40 +0100
commit66acfaf24770bcaed0d1300c38ceb414c81452db (patch)
treef3466a2786829acf6908d26287629864d06a7ac7
parent20970036076acb81ebe3d31cdb6d38609610cc0e (diff)
Force UTF-8 output
-rw-r--r--[-rwxr-xr-x]saucypy19
1 files changed, 12 insertions, 7 deletions
diff --git a/saucypy b/saucypy
index 3721ab4..fb1a5be 100755..100644
--- 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 )