aboutsummaryrefslogtreecommitdiff
path: root/name2color.py
blob: ad2551854fcf4e2379e92bd3873e6a5af5e880d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python
import sys
import hashlib
# add your favorite color code (256) here as candidates
colors = [
    63, 64, 65, 68, 103, 107,
    166, 168, 172, 208, 203,
    160, 161, 167, 137, 131
]
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 = 0
    for b in bytearray(h):
        hn = hn * 256 + int(b)
print("colour{}".format(colors[hn % len(colors)]))