Files
felhom.eu/documentation/audits/rehearsal-2026-10-20/tools/mealie_cnt.py
T

12 lines
797 B
Python

#!/usr/bin/python3
"""mealie_cnt.py [add NAME] — log in to Mealie, optionally add a recipe, print every recipe's name (B8 A.1.1)."""
import json, os, sys, urllib.parse
sys.path.insert(0, "/root/work"); from apps import http
b = "https://recipes.tester4.test"
st, out, _ = http("POST", b + "/api/auth/token", urllib.parse.urlencode({"username": "changeme@example.com", "password": os.environ["PW"]}).encode(), {"Content-Type": "application/x-www-form-urlencoded"})
H = {"Authorization": "Bearer " + json.loads(out)["access_token"]}
if len(sys.argv) > 2 and sys.argv[1] == "add":
print("add", http("POST", b + "/api/recipes", {"name": sys.argv[2]}, H)[0])
st, out, _ = http("GET", b + "/api/recipes?perPage=100", None, H)
print("recipes:", sorted(x["name"] for x in json.loads(out)["items"]))