Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat: parse scraped ingredients (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBursch authored Apr 15, 2023
1 parent a75c69c commit ef7f068
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ The `description` is a descriptive summary of the change the PR will make.
- Create a python environment `python3 -m venv venv`
- Activate your python environment `source venv/bin/activate` (environment can be deactivated with `deactivate`)
- Install dependencies `pip3 install -r requirements.txt`
- Initialize/Upgrade the sqlite database with `flask db upgrade`
- Initialize/Upgrade the SQLite database with `flask db upgrade`
- Initialize/Upgrade requirements for the recipe scraper `python -c "import nltk; nltk.download('averaged_perceptron_tagger')"`
- Run debug server with `python3 wsgi.py` or without debugging `flask run`
- The backend should be reachable at `localhost:5000`

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ COPY migrations /usr/src/kitchenowl/migrations
WORKDIR /usr/src/kitchenowl
VOLUME ["/data"]

RUN python -c "import nltk; nltk.download('averaged_perceptron_tagger')"

ENV STORAGE_PATH='/data'
ENV JWT_SECRET_KEY='PLEASE_CHANGE_ME'
ENV DEBUG='False'
Expand Down
12 changes: 11 additions & 1 deletion app/controller/recipe/recipe_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from app.models import Recipe, Item, Tag
from recipe_scrapers import scrape_me
from recipe_scrapers._exceptions import SchemaOrgException
from ingredient_parser import parse_ingredient
from werkzeug.utils import secure_filename
from .schemas import SearchByNameRequest, AddRecipe, UpdateRecipe, GetAllFilterRequest, ScrapeRecipe

Expand Down Expand Up @@ -218,7 +219,16 @@ def scrapeRecipe(args):
recipe.source = args['url']
items = {}
for ingredient in scraper.ingredients():
items[ingredient] = None
parsed = parse_ingredient(ingredient)
item = Item.find_by_name(1, parsed['name'])
if not item:
item = Item(name=parsed['name'])

items[ingredient] = item.obj_to_dict() | {
"description": ' '.join(
filter(None, [parsed['quantity'] + parsed['unit'], parsed['comment']])),
"optional": False,
}
return jsonify({
'recipe': recipe.obj_to_dict(),
'items': items,
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ greenlet==2.0.2
html-text==0.5.2
html5lib==1.1
idna==3.4
ingredient-parser-nlp==0.1.0b1
iniconfig==2.0.0
isodate==0.6.1
itsdangerous==2.1.2
Expand All @@ -43,6 +44,7 @@ mccabe==0.7.0
mf2py==1.1.2
mlxtend==0.22.0
mypy-extensions==1.0.0
nltk==3.8.1
numpy==1.24.2
packaging==23.0
pandas==2.0.0
Expand All @@ -58,6 +60,7 @@ PyJWT==2.6.0
pyparsing==3.0.9
pyRdfa3==3.5.3
pytest==7.2.2
python-crfsuite==0.9.9
python-dateutil==2.8.2
python-editor==1.0.4
pytz==2023.3
Expand All @@ -76,8 +79,10 @@ SQLAlchemy==2.0.8
threadpoolctl==3.1.0
toml==0.10.2
tomli==2.0.1
tqdm==4.65.0
typed-ast==1.5.4
types-beautifulsoup4==4.12.0.1
types-html5lib==1.1.11.10
types-requests==2.28.11.17
types-urllib3==1.26.25.10
typing_extensions==4.5.0
Expand Down

0 comments on commit ef7f068

Please sign in to comment.