How To Filter Recipe - PichapopRo/project-pantry GitHub Wiki
Filter Recipe Guide
Quick guide
Importing
First, you need to import GetDataProxy, GetDataSpoonacular, and FiterParam classes to use the filter.
from webpage.modules.proxy import GetDataProxy, GetDataSpoonacular
from webpage.modules.filter_objects import FilterParam
Setting the parameters for the filter.
Setting the parameters can be done using the FilterParam class.
param = FilterParam(offset=1, number=5)
The supported parameters are:
- offset - The starting point which the filter function retrieves the data from. It must be set during the initialization. You can edit by:
param.offset = 34 # Enter Your number here
NOTE: The offset starts at 1.
- number - The amount of the recipes you want. It must be specified during the initialization. You can edit by:
param.number = 10 # Enter you number here
- ingredients (include) - The ingredients you want to be included in the recipe. You can add by:
param.add_ingredient("Your Ingredient Name")
- equipment - The ingredient you want to include in the recipe. You can add by:
param.equipment.append("Your Equipment Name")
- diet - The diet you want the recipe to be. You can add by:
param.diet.append("Your Diet Name")
- Maximum ready time - The maximum preparation time. You can modify it by:
param.maxReadyTime = 55 # Enter your number here
- The recipe name - The string to match the recipe name. You can modify it by:
param.titleMatch = "Your Recipe Name Here"
A detailed elaboration will be added later.
Using the filter
Initializing the proxy
First, you need to initialize the GetDataProxy class.
proxy = GetDataProxy(GetDataSpoonacular)
The GetDataSpoonacular is there to be the service class. If the GetDataProxy cannot find the information from the database, it will retrieve the information via the provided service class. In this example, the service class is the GetDataSpoonacular class which fetches the data from Spoonacular.
Filtering
Filtering can be done by the following.
your_filtered_data = proxy.filter_recipe(param)
The filter_recipe method will return a list filled with the RecipeFacade class if there is data. It will return an empty list if the data cannot be found.
[The return type]
list[RecipeFacade]
Retrieving information from the RecipeFacde class
Retrieving the general recipe information.
This option allows the recipe name, id, and picture to be viewed without creating a Recipe object and wasting credits for creating it. You can view the information by:
for recipe_facade in your_filtered_list:
recipe_facade.name # Recipe name
recipe_facade.id # Recipe's Spoonacular ID
recipe_facade.picture # Recipe's picture URL
recipe_facade.favorite # Number of people who put the recipe in their favorite list.
Retrieving the whole Recipe object
You can use this option when the Recipe object is needed. For example, when the user wants to view the entire recipe. This can be done by:
for recipe_facade in your_filtered_list:
recipe_object = recipe_facade.get_recipe() # Returns the recipe object