-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmealchk.py
executable file
·43 lines (34 loc) · 1.33 KB
/
mealchk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# mealchk-cli
# mealchk.py
import re
# Load list of prohibited ingredients
with open("ingredients.txt") as f:
prohibitedList = f.read().splitlines()
def analyze(ingredientsRaw):
# Create variables
passFlag = True
ingredientList = []
detectedList = []
passedList = []
failedList = []
# Split input by comma seperation, while ignoring anything in brackets
# regex = "/,(?![^(]*\)) /;"
ingredients = ingredientsRaw.lstrip().lower().replace("ingredients", "")
ingredients = re.split(r",(?![^(]*\))", ingredients)
# # Trim each ingredient further
for i in ingredients:
formattedIngredient = i.strip().replace("\n", " ").replace(".", "")
formattedIngredient = formattedIngredient.strip()
# Append (if not duplicate)
if formattedIngredient not in ingredientList:
ingredientList.append(formattedIngredient)
print("Ingredients list: \n", ingredientList)
for ingredient in ingredientList:
# print("Ingredient: ", ingredient)
for prohibited in prohibitedList:
if ingredient.find(prohibited) > 0 or ingredient == prohibited:
# print("Found: ", (ingredient))
detectedList.append(ingredient)
# print("Found: ", ingredient)
print("\n", "Warning: ", detectedList)