aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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
+
+