1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

tarot: generalize

This commit is contained in:
2025-12-20 11:31:12 +01:00
parent dd75268d60
commit a0f7867a25
3 changed files with 36 additions and 33 deletions

View File

@@ -20,7 +20,7 @@ in {
./scrabble.nix ./scrabble.nix
# ./onlyoffice.nix # ./onlyoffice.nix
./retiolum-map.nix ./retiolum-map.nix
./tarot.nix ./oracle
./tt-rss.nix ./tt-rss.nix
./weechat.nix ./weechat.nix
../../configs/monitoring.nix ../../configs/monitoring.nix

View File

@@ -21,39 +21,16 @@ in
enable = true; enable = true;
serviceConfig.Type = "simple"; serviceConfig.Type = "simple";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
environment = {
TAROT_FILES = tarotFiles;
TAROT_PORT = toString tarotPort;
};
serviceConfig.ExecStart = pkgs.writers.writePython3 "tarot-server" { serviceConfig.ExecStart = pkgs.writers.writePython3 "tarot-server" {
libraries = py: [ py.pillow py.flask ]; libraries = py: [
} '' py.pillow
from flask import Flask, send_file py.flask
from pathlib import Path ];
from random import choice, randint } ./tarot.py;
from io import BytesIO
from PIL import Image
app = Flask(__name__)
TAROT_DIR = Path("${tarotFiles}")
@app.route("/")
def tarot():
card_path = choice(list(TAROT_DIR.glob("*")))
with Image.open(card_path) as img:
if randint(0, 1):
img = img.rotate(180)
buf = BytesIO()
img.save(buf, format="JPEG")
buf.seek(0)
return send_file(
buf,
mimetype='image/jpeg',
as_attachment=False
)
if __name__ == "__main__":
app.run(port=${toString tarotPort})
'';
}; };
niveum.passport.services = [ niveum.passport.services = [

View File

@@ -0,0 +1,26 @@
from flask import Flask, send_file
from pathlib import Path
from random import choice, randint
from io import BytesIO
from PIL import Image
import os
app = Flask(__name__)
TAROT_DIR = Path(os.environ["TAROT_FILES"])
@app.route("/")
def tarot():
card_path = choice(list(TAROT_DIR.glob("*")))
with Image.open(card_path) as img:
if randint(0, 1):
img = img.rotate(180)
buf = BytesIO()
img.save(buf, format="JPEG")
buf.seek(0)
return send_file(buf, mimetype="image/jpeg", as_attachment=False)
if __name__ == "__main__":
app.run(port=int(os.environ["TAROT_PORT"]))