diff options
author | Determinant <tederminant@gmail.com> | 2020-05-22 11:12:25 -0400 |
---|---|---|
committer | Determinant <tederminant@gmail.com> | 2020-05-22 11:12:25 -0400 |
commit | f762c7f81f0c093470be9ebe91dcfc08cb6fffe4 (patch) | |
tree | f35427b570d97e1696492cfaf06767b3cb7cd35b | |
parent | fdf918d206cd322f69f574226f6fe4f01936e6af (diff) |
unify the color for python3 and python2
-rwxr-xr-x | name2color.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/name2color.py b/name2color.py index 7c1d11b..ad25518 100755 --- a/name2color.py +++ b/name2color.py @@ -1,6 +1,5 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python import sys -import struct import hashlib # add your favorite color code (256) here as candidates colors = [ @@ -12,5 +11,7 @@ h = hashlib.sha1(sys.argv[1].encode('utf-8')).digest() if sys.version_info.major == 3: hn = int.from_bytes(h, byteorder='big') else: - (hn,) = struct.unpack('>Q12x', h) + hn = 0 + for b in bytearray(h): + hn = hn * 256 + int(b) print("colour{}".format(colors[hn % len(colors)])) |