From f762c7f81f0c093470be9ebe91dcfc08cb6fffe4 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 22 May 2020 11:12:25 -0400 Subject: unify the color for python3 and python2 --- name2color.py | 7 ++++--- 1 file 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)])) -- cgit v1.2.3