Skip to content

Commit

Permalink
description and image src details
Browse files Browse the repository at this point in the history
  • Loading branch information
dspray95 committed Mar 17, 2019
1 parent bcec77a commit e8e362a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 50 deletions.
144 changes: 102 additions & 42 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from controller import Controller

controller = Controller()
controller.run_spider(True)
Binary file added src/__pycache__/controller.cpython-37.pyc
Binary file not shown.
Binary file modified src/__pycache__/recipe.cpython-37.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions src/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,3 @@ def run_spider(verbose=False):
if verbose:
print(data)


controller = Controller()
controller.run_spider(True)
8 changes: 6 additions & 2 deletions src/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ def to_dict(self):

class Recipe:

def __init__(self, name, author, nutrition, ingredients, method, time, difficulty, servings):
def __init__(self, name, author, description, nutrition, ingredients, method, time, difficulty, servings, img_url):
self.name = name
self.author = author
self.description = description
self.nutrition = nutrition
self.ingredients = ingredients
self.method = method
self.time = time,
self.difficulty = difficulty,
self.servings = servings
self.img_url = img_url

def to_dict(self):
return {
"name": self.name,
"author": self.author,
"description": self.description,
"nutrition": self.nutrition.to_dict(),
"ingredients": self.ingredients,
"method": self.method,
"time": self.time,
"difficulty": self.difficulty,
"servings": self.servings
"servings": self.servings,
"img_url": self.img_url
}
Binary file not shown.
8 changes: 5 additions & 3 deletions src/recipe_builder/recipe_builder/spiders/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def parse(self, response):
header = response.xpath('//div[contains(@class, "recipe-header")]')
recipe_title = header.xpath('h1[contains(@class, "recipe-header__title")]/text()')
attrib = header.xpath('//div[contains(@class, "recipe-header__chef")]/span/a/text()')

img = header.xpath('//img[contains(@itemprop, "image")]/@src')
description = header.xpath('//div[contains(@class, "recipe-header__description")]//text()').get()
time = {
"prep": {
'hrs': header.xpath('//span[contains(@class, "recipe-details__cooking-time-prep")]/'
Expand Down Expand Up @@ -78,12 +79,13 @@ def parse(self, response):
# The full text of the ingredients will be in the content attribute of the li tag
ingredients = details.xpath('section[contains(@id, "recipe-ingredients")]//'
'div[contains(@class, "ingredients-list__content")]/ul/li/@content')

# TODO Check for final method step, sometimes the beeb offers a suggestion with a link to another recipe
method = details.xpath('section[contains(@id, "recipe-method")]//'
'div[contains(@class, "method")]/ol/li/p/text()')

recipe_object = Recipe(recipe_title.get(), attrib.get(), nutrition_object, ingredients.getall(),
method.getall(), time, difficulty, servings)
recipe_object = Recipe(recipe_title.get(), attrib.get(), description, nutrition_object, ingredients.getall(),
method.getall(), time, difficulty, servings, img.get())

# self, name, author, nutrition, ingredients, method
return recipe_object.to_dict()
Expand Down

0 comments on commit e8e362a

Please sign in to comment.