Added parser for akispetretzikis.com
This commit is contained in:
parent
b78cba476b
commit
5823a231a4
2 changed files with 37 additions and 0 deletions
|
@ -13,6 +13,7 @@ from parsers.kochbar import Kochbar
|
|||
from parsers.hostthetoast import Hostthetoast
|
||||
from parsers.thewoksoflife import Thewoksoflife
|
||||
from parsers.glebekitchen import GlebeKitchen
|
||||
from parsers.akispetretzikis import AkisPetretzikis
|
||||
|
||||
# Must exclude the "www" portion of the URL
|
||||
PARSERS = {
|
||||
|
@ -30,6 +31,7 @@ PARSERS = {
|
|||
'kochbar.de' : Kochbar,
|
||||
'thewoksoflife.com': Thewoksoflife,
|
||||
'glebekitchen.com': GlebeKitchen,
|
||||
'akispetretzikis.com': AkisPetretzikis
|
||||
}
|
||||
|
||||
def getParser(domain):
|
||||
|
|
35
parsers/akispetretzikis.py
Normal file
35
parsers/akispetretzikis.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
from re import split
|
||||
from parsers.recipe import Recipe
|
||||
|
||||
|
||||
class AkisPetretzikis(Recipe):
|
||||
|
||||
def get_json_recipe(self, d):
|
||||
recipe = {}
|
||||
if d['@type'] == 'Recipe':
|
||||
recipe['name'] = d['name']
|
||||
recipe['description'] = d['description']
|
||||
recipe['ingredients'] = d['recipeIngredient']
|
||||
recipe['instructions'] = split(r'\r\n', d['recipeInstructions'])
|
||||
recipe['instructions'] = [instruction for instruction in recipe['instructions'] if instruction]
|
||||
recipe['image'] = d['image']
|
||||
|
||||
return recipe
|
||||
|
||||
def Parse(self, url):
|
||||
recipe = {}
|
||||
recipe['url'] = url
|
||||
recipe['source'] = 'akispetretzikis.com'
|
||||
|
||||
soup = self.fetch_soup(url)
|
||||
|
||||
results = soup.find_all('script', {'type': 'application/ld+json'})
|
||||
for result in results:
|
||||
d = json.loads(result.contents[0])
|
||||
if d['@type'].lower() == 'recipe':
|
||||
parsed_recipe = self.get_json_recipe(d)
|
||||
recipe.update(parsed_recipe)
|
||||
else:
|
||||
continue
|
||||
return recipe
|
Loading…
Reference in a new issue