aboutsummaryrefslogtreecommitdiffhomepage
path: root/apioforum/util.py
blob: 64bdf20b6eb792484a46ed7f1ee1d78e444ee128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# various utility things

import hsluv
import hashlib

# same algorithm as xep-0392
def gen_colour(s):
    b=s.encode("utf-8")
    h=hashlib.sha1(b)
    two_bytes=h.digest()[:2]
    val = int.from_bytes(two_bytes, 'little')
    angle = 360*(val/65536)
    col = hsluv.hsluv_to_hex([angle, 80, 70])
    return col