Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay Goel
authored and
Jay Goel
committed
Apr 18, 2020
1 parent
edd0ff5
commit cac857c
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |