aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-05-22 11:12:25 -0400
committerDeterminant <tederminant@gmail.com>2020-05-22 11:12:25 -0400
commitf762c7f81f0c093470be9ebe91dcfc08cb6fffe4 (patch)
treef35427b570d97e1696492cfaf06767b3cb7cd35b
parentfdf918d206cd322f69f574226f6fe4f01936e6af (diff)
unify the color for python3 and python2
-rwxr-xr-xname2color.py7
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)]))