-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmealie_import.py
More file actions
48 lines (41 loc) · 1.31 KB
/
mealie_import.py
File metadata and controls
48 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import requests
import os
from dotenv import load_dotenv
load_dotenv()
# Konfiguration
MEALIE_URL = os.getenv("MEALIE_URL")
API_KEY = os.getenv("API_KEY")
JSON_URL = "https://raw.githubusercontent.com/mealie-recipes/mealie/refs/heads/mealie-next/mealie/repos/seed/resources/foods/locales/de-DE.json" #original language json -> https://github.com/mealie-recipes/mealie/tree/mealie-next/mealie/repos/seed/resources/foods/locales
headers = {
"Authorization": f"Bearer {API_KEY}",
"accept": "application/json",
"Content-Type": "application/json"
}
response = requests.get(JSON_URL)
response.raise_for_status()
food_dict = response.json()
for key, value in food_dict.items():
if isinstance(value, dict) and "name" in value:
name = value["name"]
elif isinstance(value, str):
name = value
else:
continue
food_obj = {
"name": name,
"pluralName": "",
"description": "",
"extras": {},
"aliases": [],
"householdsWithIngredientFood": []
}
api_response = requests.post(
f"{MEALIE_URL}/api/foods",
headers=headers,
json=food_obj
)
if api_response.status_code == 201:
print(f"Imported: {name}")
else:
print(f"Error by {name}: {api_response.status_code} {api_response.text}")