From ca9059374bae63dcf47b0ffcaa57b43ae608c309 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 18 Jul 2021 15:16:46 +0000 Subject: and i forgot to add util.py as well --- apioforum/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 apioforum/util.py diff --git a/apioforum/util.py b/apioforum/util.py new file mode 100644 index 0000000..64bdf20 --- /dev/null +++ b/apioforum/util.py @@ -0,0 +1,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 + + -- cgit v1.2.3