Skip to content

Commit

Permalink
add lovingitvegan
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Goel authored and Jay Goel committed Apr 18, 2020
1 parent edd0ff5 commit cac857c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parsers/__init__.py
@@ -1,11 +1,13 @@
from parsers.gimmesomeoven import Gimmesomeoven
from parsers.smittenkitchen import Smittenkitchen
from parsers.letsdishrecipes import Letsdishrecipes
from parsers.lovingitvegan import Lovingitvegan

PARSERS = {
'www.gimmesomeoven.com': Gimmesomeoven,
'smittenkitchen.com': Smittenkitchen,
'letsdishrecipes.com': Letsdishrecipes,
'lovingitvegan.com': Lovingitvegan,
}

def getParser(domain):
Expand Down
39 changes: 39 additions & 0 deletions parsers/lovingitvegan.py
@@ -0,0 +1,39 @@
import json

from parsers.recipe import Recipe

class Lovingitvegan(Recipe):

def get_json_recipe(self, d):
recipe = {}
for r in d['@graph']:
print(r['@type'])

if not isinstance(r['@type'], str):
continue

if r['@type'].lower() != 'recipe':
continue

recipe['name'] = r['name']
recipe['description'] = r['description']
recipe['ingredients'] = r['recipeIngredient']
recipe['instructions'] = [i['text'] for i in r['recipeInstructions']]
recipe['image'] = r['image'][0]

return recipe

def Parse(self, url):
recipe = {}
recipe['url'] = url
recipe['source'] = 'lovingitvegan.com'

soup = self.fetch_soup(url)

result = soup.find('script', {'type': 'application/ld+json'})

d = json.loads(result.contents[0])
parsed_recipe = self.get_json_recipe(d)
recipe.update(parsed_recipe)

return recipe

0 comments on commit cac857c

Please sign in to comment.