summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-07-18 15:16:46 +0000
committerubq323 <ubq323>2021-07-18 15:16:46 +0000
commitca9059374bae63dcf47b0ffcaa57b43ae608c309 (patch)
tree32566e71ee78dcac44c835914982e94186d226f0
parent8b022f838f507c1a6fcc67edc97fecdd17423f06 (diff)
and i forgot to add util.py as well
-rw-r--r--apioforum/util.py16
1 files changed, 16 insertions, 0 deletions
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
+
+