2021-04-07 18:38:06 -08:00
!!! info
2021-06-04 18:45:13 -08:00
This guide was submitted by a community member. Find something wrong? Submit a PR to get it fixed!
2021-04-07 18:38:06 -08:00
Recipes can be imported in bulk from a file containing a list of URLs. This can be done using the following bash or python scripts with the `list` file containing one URL per line.
#### Bash
```bash
#!/bin/bash
2022-09-25 23:17:27 +00:00
function authentication () {
2021-04-07 18:38:06 -08:00
auth=$(curl -X 'POST' \
"$3/api/auth/token" \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=&username='$1'&password='$2'&scope=&client_id=&client_secret=')
echo $auth | sed -e 's/.*token":"\(.*\)",.*/\1/'
}
function import_from_file () {
while IFS= read -r line
do
echo $line
curl -X 'POST' \
2024-09-30 10:52:13 -05:00
"$3/api/recipes/create/url" \
2021-04-07 18:38:06 -08:00
-H "Authorization: Bearer $2" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"url": "'$line'" }'
echo
done < "$1"
}
input="list"
2023-09-23 15:56:34 +00:00
mail="changeme@example .com"
2021-04-07 18:38:06 -08:00
password="MyPassword"
mealie_url=http://localhost:9000
2022-09-25 23:17:27 +00:00
token=$(authentication $mail $password $mealie_url)
2021-04-07 18:38:06 -08:00
import_from_file $input $token $mealie_url
```
2022-06-15 20:50:19 +01:00
#### Go
See <a href="https://github.com/Jleagle/mealie-importer" target="_blank">Jleagle/mealie-importer</a>.
2021-04-07 18:38:06 -08:00
#### Python
```python
import requests
import re
2022-09-25 23:17:27 +00:00
def authentication(mail, password, mealie_url):
2021-04-07 18:38:06 -08:00
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'grant_type': '',
'username': mail,
'password': password,
'scope': '',
'client_id': '',
'client_secret': ''
}
auth = requests.post(mealie_url + "/api/auth/token", headers=headers, data=data)
token = re.sub(r'.*token":"(.*)",.*', r'\1', auth.text)
return token
def import_from_file(input_file, token, mealie_url):
with open(input_file) as fp:
for l in fp:
line = re.sub(r'(.*)\n', r'\1', l)
print(line)
headers = {
'Authorization': "Bearer " + token,
'accept': 'application/json',
'Content-Type': 'application/json'
}
data = {
'url': line
}
2024-09-30 10:52:13 -05:00
response = requests.post(mealie_url + "/api/recipes/create/url", headers=headers, json=data)
2021-04-07 18:38:06 -08:00
print(response.text)
input_file="list"
2023-09-23 15:56:34 +00:00
mail="changeme@example .com"
2021-04-07 18:38:06 -08:00
password="MyPassword"
mealie_url="http://localhost:9000"
2022-09-25 23:17:27 +00:00
token = authentication(mail, password, mealie_url)
2021-04-07 18:38:06 -08:00
import_from_file(input_file, token, mealie_url)
```