Example usage

To use intakeinformer in a project:

pip install intakeinformer
Collecting intakeinformer
  Downloading intakeinformer-1.0.0-py3-none-any.whl.metadata (4.5 kB)
Collecting beautifulsoup4<5.0.0,>=4.9.3 (from intakeinformer)
  Downloading beautifulsoup4-4.12.2-py3-none-any.whl (142 kB)
?25l                                              0.0/143.0 kB ? eta -:--:--
     ━━━━━━━━━━━━━━━━━                        61.4/143.0 kB 2.3 MB/s eta 0:00:01
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 143.0/143.0 kB 3.3 MB/s eta 0:00:00
?25h
Collecting matplotlib<4.0.0,>=3.8.2 (from intakeinformer)
  Downloading matplotlib-3.8.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting numpy<2.0.0,>=1.26.2 (from intakeinformer)
  Downloading numpy-1.26.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
?25l                                              0.0/61.2 kB ? eta -:--:--
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 6.3 MB/s eta 0:00:00
?25h
Collecting pandas<3.0.0,>=2.1.4 (from intakeinformer)
  Downloading pandas-2.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)
Requirement already satisfied: requests<3.0.0,>=2.31.0 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from intakeinformer) (2.31.0)
Collecting soupsieve>1.2 (from beautifulsoup4<5.0.0,>=4.9.3->intakeinformer)
  Downloading soupsieve-2.5-py3-none-any.whl.metadata (4.7 kB)
Collecting contourpy>=1.0.1 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading contourpy-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (5.8 kB)
Collecting cycler>=0.10 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)
Collecting fonttools>=4.22.0 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading fonttools-4.46.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (156 kB)
?25l                                              0.0/156.2 kB ? eta -:--:--
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 156.2/156.2 kB 6.3 MB/s eta 0:00:00
?25h
Collecting kiwisolver>=1.3.1 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading kiwisolver-1.4.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.4 kB)
Requirement already satisfied: packaging>=20.0 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->intakeinformer) (23.2)
Collecting pillow>=8 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading Pillow-10.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (9.5 kB)
Collecting pyparsing>=2.3.1 (from matplotlib<4.0.0,>=3.8.2->intakeinformer)
  Downloading pyparsing-3.1.1-py3-none-any.whl.metadata (5.1 kB)
Requirement already satisfied: python-dateutil>=2.7 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from matplotlib<4.0.0,>=3.8.2->intakeinformer) (2.8.2)
Collecting pytz>=2020.1 (from pandas<3.0.0,>=2.1.4->intakeinformer)
  Downloading pytz-2023.3.post1-py2.py3-none-any.whl.metadata (22 kB)
Collecting tzdata>=2022.1 (from pandas<3.0.0,>=2.1.4->intakeinformer)
  Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
?25l                                              0.0/341.8 kB ? eta -:--:--
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 337.9/341.8 kB 10.7 MB/s eta 0:00:01
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 kB 8.5 MB/s eta 0:00:00
?25hRequirement already satisfied: charset-normalizer<4,>=2 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->intakeinformer) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->intakeinformer) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->intakeinformer) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from requests<3.0.0,>=2.31.0->intakeinformer) (2023.11.17)
Requirement already satisfied: six>=1.5 in /home/docs/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib<4.0.0,>=3.8.2->intakeinformer) (1.16.0)
Downloading intakeinformer-1.0.0-py3-none-any.whl (15 kB)
Downloading matplotlib-3.8.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB)
?25l                                            0.0/11.6 MB ? eta -:--:--
   ━                                        0.4/11.6 MB 11.0 MB/s eta 0:00:02
   ━━╸                                      0.8/11.6 MB 12.1 MB/s eta 0:00:01
   ━━━━╸                                    1.4/11.6 MB 13.0 MB/s eta 0:00:01
   ━━━━━━                                   1.8/11.6 MB 13.3 MB/s eta 0:00:01
   ━━━━━━━━╸                                2.5/11.6 MB 14.7 MB/s eta 0:00:01
   ━━━━━━━━━━━╸                             3.3/11.6 MB 16.0 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━╸                          4.3/11.6 MB 17.6 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━                       5.3/11.6 MB 19.3 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━╸                  6.6/11.6 MB 20.9 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━╸             8.0/11.6 MB 23.0 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━        9.6/11.6 MB 25.1 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 11.6/11.6 MB 32.3 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 11.6/11.6 MB 32.4 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.6/11.6 MB 28.4 MB/s eta 0:00:00
?25hDownloading numpy-1.26.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.9 MB)
?25l                                            0.0/17.9 MB ? eta -:--:--
   ━━━━━                                    2.4/17.9 MB 75.8 MB/s eta 0:00:01
   ━━━━━━━━━━╸                              4.7/17.9 MB 69.6 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━                        7.8/17.9 MB 75.0 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━                11.4/17.9 MB 81.6 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━      15.7/17.9 MB 105.4 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 17.9/17.9 MB 116.9 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 17.9/17.9 MB 116.9 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.9/17.9 MB 67.7 MB/s eta 0:00:00
?25hDownloading pandas-2.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.7 MB)
?25l                                            0.0/11.7 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━╸                       5.2/11.7 MB 155.2 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸    10.7/11.7 MB 154.4 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 11.7/11.7 MB 151.3 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.7/11.7 MB 93.2 MB/s eta 0:00:00
?25h
Downloading contourpy-1.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (303 kB)
?25l                                            0.0/303.9 kB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 303.9/303.9 kB 35.7 MB/s eta 0:00:00
?25hDownloading cycler-0.12.1-py3-none-any.whl (8.3 kB)
Downloading fonttools-4.46.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB)
?25l                                            0.0/4.9 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  4.8/4.9 MB 145.7 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.9/4.9 MB 85.7 MB/s eta 0:00:00
?25hDownloading kiwisolver-1.4.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB)
?25l                                            0.0/1.5 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 63.2 MB/s eta 0:00:00
?25hDownloading Pillow-10.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (3.6 MB)
?25l                                            0.0/3.6 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸ 3.6/3.6 MB 143.6 MB/s eta 0:00:01
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 85.0 MB/s eta 0:00:00
?25hDownloading pyparsing-3.1.1-py3-none-any.whl (103 kB)
?25l                                            0.0/103.1 kB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.1/103.1 kB 11.9 MB/s eta 0:00:00
?25h
Downloading pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
?25l                                            0.0/502.5 kB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.5/502.5 kB 48.1 MB/s eta 0:00:00
?25hDownloading soupsieve-2.5-py3-none-any.whl (36 kB)
Installing collected packages: pytz, tzdata, soupsieve, pyparsing, pillow, numpy, kiwisolver, fonttools, cycler, pandas, contourpy, beautifulsoup4, matplotlib, intakeinformer
Successfully installed beautifulsoup4-4.12.2 contourpy-1.2.0 cycler-0.12.1 fonttools-4.46.0 intakeinformer-1.0.0 kiwisolver-1.4.5 matplotlib-3.8.2 numpy-1.26.2 pandas-2.1.4 pillow-10.1.0 pyparsing-3.1.1 pytz-2023.3.post1 soupsieve-2.5 tzdata-2023.3
Note: you may need to restart the kernel to use updated packages.
from intakeinformer import get_calories_for_food_query, dri_benchmark
'''
Because the Jupyter notebook environment does not support the input() function, 
But input() is used in two core functions that users will interact (get_calories_for_food_query() & dri_benchmark() to capture input.

I need to set up predefined selection patterns for demonstration purposes with .ipynb file ONLY.

You do not need to use the unittest.mock library

'''
from unittest.mock import patch # bypass the interactive input requirement in Jupyter notebooks

import os
# Please follow the steps outlined in the "Getting Started with IntakeInformer" section to obtain a valid USDA API KEY.
# The example here is based on the API Key of the developer.
os.environ['POETRY_FDC_API_KEY'] = 'your_API_Key_here'
my_api_key = os.getenv('POETRY_FDC_API_KEY')
'''

Predefined selections for demonstration purposes!

Predefine the mock inputs for each call to input()

In a real interactive environment (like a Python shell or a script), 
the function will behave normally and prompt the user for input.
'''

# Assuming these are the indices of items a user might choose
# For example, the get_calories_for_food_query() function calls input() twice and unittest.mock library simulates
# user selecting the first item both times.
mock_inputs = ['1', '1'] 

with patch('builtins.input', side_effect=mock_inputs):
    calorie_info = get_calories_for_food_query(my_api_key, 'apple', 'banana')

print(calorie_info)
HTTP error occurred: 403 Client Error: Forbidden for url: https://api.nal.usda.gov/fdc/v1/foods/search?api_key=your_API_Key_here&pageSize=10&pageNumber=2&dataType=Branded&sortBy=publishedDate&sortOrder=asc&query=apple
Select an item for 'apple':
No foods found.
No valid selection made for 'apple'. Skipping...
HTTP error occurred: 403 Client Error: Forbidden for url: https://api.nal.usda.gov/fdc/v1/foods/search?api_key=your_API_Key_here&pageSize=10&pageNumber=2&dataType=Branded&sortBy=publishedDate&sortOrder=asc&query=banana
Select an item for 'banana':
No foods found.
No valid selection made for 'banana'. Skipping...
No calorie information available. No valid selections were made.
'''
Similarly, because the dri_benchmark() function calls input() four times and unittest.mock library simulates
user selection for each time.
'''

mock_inputs = ['9', '8', '3', '3'] 

with patch('builtins.input', side_effect=mock_inputs):
    dri_benchmark(my_api_key, "apple", "cheedar cheese")
HTTP error occurred: 403 Client Error: Forbidden for url: https://api.nal.usda.gov/fdc/v1/foods/search?api_key=your_API_Key_here&pageSize=10&pageNumber=2&dataType=Branded&sortBy=publishedDate&sortOrder=asc&query=apple
No foods found.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 9
      6 mock_inputs = ['9', '8', '3', '3'] 
      8 with patch('builtins.input', side_effect=mock_inputs):
----> 9     dri_benchmark(my_api_key, "apple", "cheedar cheese")

File ~/checkouts/readthedocs.org/user_builds/intakeinformer/envs/latest/lib/python3.12/site-packages/intakeinformer/main_functions.py:149, in dri_benchmark(FDC_Key, *food_queries)
    146 selected_food = get_user_food_selection(food_data)
    148 # Check if selected_food is not empty before proceeding
--> 149 if not selected_food.empty:
    150     nutrients = extract_nutrients(selected_food['foodNutrients'])
    151     combined_nutrients.update(nutrients)

AttributeError: 'NoneType' object has no attribute 'empty'