Coverage for cookbook/helper/fdc_helper.py: 0%
13 statements
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
« prev ^ index » next coverage.py v7.4.0, created at 2023-12-29 00:47 +0100
1import json
4def get_all_nutrient_types():
5 f = open('') # <--- download the foundation food or any other dataset and retrieve all nutrition ID's from it https://fdc.nal.usda.gov/download-datasets.html
6 json_data = json.loads(f.read())
8 nutrients = {}
9 for food in json_data['FoundationFoods']:
10 for entry in food['foodNutrients']:
11 nutrients[entry['nutrient']['id']] = {'name': entry['nutrient']['name'], 'unit': entry['nutrient']['unitName']}
13 nutrient_ids = list(nutrients.keys())
14 nutrient_ids.sort()
15 for nid in nutrient_ids:
16 print('{', f'value: {nid}, text: "{nutrients[nid]["name"]} [{nutrients[nid]["unit"]}] ({nid})"', '},')
19get_all_nutrient_types()