⬆️ update to current tandoor api (+ some error handling)

This commit is contained in:
neingeist 2026-04-08 23:13:31 +02:00
parent 25b65f8dc8
commit 6eac2264aa

View file

@ -11,7 +11,7 @@ if TANDOOR_API_TOKEN:
def fetch_keyword_id(keyword):
endpoint = "/api/keyword"
endpoint = "/api/keyword/"
page = 1
while True:
@ -23,7 +23,11 @@ def fetch_keyword_id(keyword):
print(f"Error: Received status code {response.status_code}")
return None
data = response.json()
try:
data = response.json()
except requests.exceptions.JSONDecodeError:
print(f"Error: No JSON returned")
return None
results = data.get("results", [])
for item in results:
@ -40,7 +44,7 @@ def fetch_keyword_id(keyword):
def fetch_recipes(keyword_id):
recipes = []
endpoint = "/api/recipe"
endpoint = "/api/recipe/"
page = 1
while True:
@ -53,7 +57,11 @@ def fetch_recipes(keyword_id):
print(f"Error: Received status code {response.status_code}")
return None
data = response.json()
try:
data = response.json()
except requests.exceptions.JSONDecodeError:
print(f"Error: No JSON returned")
return None
results = data.get("results", [])
for item in results:
@ -69,15 +77,23 @@ def fetch_recipes(keyword_id):
def fetch_recipe(recipe_id):
endpoint = "/api/recipe"
endpoint = "/api/recipe/"
response = requests.get(f"{TANDOOR_URL}/api/recipe/{recipe_id}", headers=headers)
params = {}
response = requests.get(
f"{TANDOOR_URL}{endpoint}{recipe_id}/", params=params, headers=headers
)
if response.status_code != 200:
print(f"Error: Received status code {response.status_code}")
return None
recipe = response.json()
try:
data = response.json()
except requests.exceptions.JSONDecodeError:
print(f"Error: No JSON returned")
return None
recipe = data
return recipe