This is a nutrient importer for Tandoor, an open source recipe manager.
Tandoor has the possibility to add Foods
which then can be used in recipes. For the different Foods
properties like "Sugars", "Fats" or "Energy" can be added.
These will be used to calculate the total nutrients of a recipe.
Because adding all the properties to a food item by hand is quite annoying I built this importer to import data provided by the USDA Food Database using the API.
- The program reads the appsettings.json to find the Tandoor instance and to get the needed API-Keys for Tandoor and the USDA FDC database.
- After that all properties and all foods are retrieved from the Tandoor instance.
- For each food item retrieved from Tandoor the FDC ID of that food item (the ID is retrieved primarily from the "URL" field of a
Food
. If no URL is given the program tries to get it from the "FDC ID" field, or asks the user if the program is run in interactive mode) is used to query the FDC database for nutrients. - All nutrients of a food item are retrieved, then the nutrients that are not present in Tandoor are filtered out.
- The data retrieved from the FDC database is added to the Tandoor food.
- The updated food is pushed to the Tandoor database.
- Create an API key for your Tandoor instance under
<your-tandoor-endpoint>/settings
in the API section. Make sure the token hasread write
as the scope. - Create an API key for the USDA FDC database by signing up here. The API key will be sent to you via e-mail.
- Open the FDC page for every food you want to update (e.g. this for maple syrup)
- Either copy the URL into the "URL" field of the food. The field can be found by editing a food item and going to the "More" section.
- Or go to the admin view of your foods
<your-tandoor-endpoint>/admin/cookbook/food/
and edit the food there to enter the FDC ID. - Note that the URL will be preferred if URL and FDC ID are set.
- You can also run the program in interactive mode (
./tandoor_importer --interactive
) to be asked for an FDC ID if your food does not have one assigned.
- Make sure that every property you have created in Tandoor also has the corresponding FDC ID assigned so the matching can work.
- Copy appsettings.template.json to
appsettings.json
and add your Tandoor endpoint as well as the API key to it. - Run the program using
./tandoor_importer
. Refer to the Parameters section for configuration. - All food items for which an FDC ID was assigned should now have values for all your properties.
Name | short name | Description | Required? | Default |
---|---|---|---|---|
--interactive | -i | When set the program asks the user to provide an FDC ID when none was found | No | false |
--override | -o | When set the program overrides properties that are already present. | No | false |
Name | short name | Description | Required? | Default |
---|---|---|---|---|
--log-level | -l | Sets the log level [One of: trace, debug, info, warning, error] | No | info |