fixes for essen-und-trinken, HTTP status codes
This commit is contained in:
parent
2c71feb998
commit
e932be7d92
2 changed files with 6 additions and 10 deletions
4
main.py
4
main.py
|
@ -46,12 +46,12 @@ def recipe():
|
||||||
try:
|
try:
|
||||||
recipe = scrape_recipe(url)
|
recipe = scrape_recipe(url)
|
||||||
if not recipe:
|
if not recipe:
|
||||||
return render_template('unsupported.html', domain=domain)
|
return render_template('unsupported.html', domain=domain), 501
|
||||||
|
|
||||||
return render_template('recipe.html', recipe=recipe)
|
return render_template('recipe.html', recipe=recipe)
|
||||||
except:
|
except:
|
||||||
logging.exception(url)
|
logging.exception(url)
|
||||||
return render_template('parse_error.html', domain=domain)
|
return render_template('parse_error.html', domain=domain), 418
|
||||||
|
|
||||||
@app.route('/supported-websites')
|
@app.route('/supported-websites')
|
||||||
def supported_websites():
|
def supported_websites():
|
||||||
|
|
|
@ -10,8 +10,8 @@ class EssenUndTrinken(Recipe):
|
||||||
recipe['name'] = d['name']
|
recipe['name'] = d['name']
|
||||||
recipe['description'] = d.get('description', '')
|
recipe['description'] = d.get('description', '')
|
||||||
recipe['ingredients'] = d['recipeIngredient']
|
recipe['ingredients'] = d['recipeIngredient']
|
||||||
recipe['instructions'] = self.cleanhtml(d['recipeInstructions']).split('\n')
|
recipe['instructions'] = d['recipeInstructions']
|
||||||
recipe['image'] = d['image']
|
recipe['image'] = d['image'][0]['url']
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
|
@ -24,13 +24,9 @@ class EssenUndTrinken(Recipe):
|
||||||
|
|
||||||
result = soup.find_all('script', {'type': 'application/ld+json'})
|
result = soup.find_all('script', {'type': 'application/ld+json'})
|
||||||
|
|
||||||
d = json.loads(result[1].contents[0])
|
d = json.loads(result[0].contents[0])[0]
|
||||||
|
|
||||||
parsed_recipe = self.get_json_recipe(d)
|
parsed_recipe = self.get_json_recipe(d)
|
||||||
recipe.update(parsed_recipe)
|
recipe.update(parsed_recipe)
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
def cleanhtml(self, txt):
|
|
||||||
cleanr = re.compile('<.*?>')
|
|
||||||
return re.sub(cleanr, '', txt.lstrip(" \n"))
|
|
Loading…
Reference in a new issue