diff --git a/systems/makanek/configuration.nix b/systems/makanek/configuration.nix index c61609a..c524d7f 100644 --- a/systems/makanek/configuration.nix +++ b/systems/makanek/configuration.nix @@ -20,7 +20,7 @@ in { ./scrabble.nix # ./onlyoffice.nix ./retiolum-map.nix - ./tarot.nix + ./oracle ./tt-rss.nix ./weechat.nix ../../configs/monitoring.nix diff --git a/systems/makanek/tarot.nix b/systems/makanek/oracle/default.nix similarity index 61% rename from systems/makanek/tarot.nix rename to systems/makanek/oracle/default.nix index 65a5bb6..e914359 100644 --- a/systems/makanek/tarot.nix +++ b/systems/makanek/oracle/default.nix @@ -21,39 +21,16 @@ in enable = true; serviceConfig.Type = "simple"; wantedBy = [ "multi-user.target" ]; + environment = { + TAROT_FILES = tarotFiles; + TAROT_PORT = toString tarotPort; + }; serviceConfig.ExecStart = pkgs.writers.writePython3 "tarot-server" { - libraries = py: [ py.pillow py.flask ]; - } '' - from flask import Flask, send_file - from pathlib import Path - from random import choice, randint - 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}) - ''; + libraries = py: [ + py.pillow + py.flask + ]; + } ./tarot.py; }; niveum.passport.services = [ diff --git a/systems/makanek/oracle/tarot.py b/systems/makanek/oracle/tarot.py new file mode 100644 index 0000000..c9a784e --- /dev/null +++ b/systems/makanek/oracle/tarot.py @@ -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"]))