fixes for essen-und-trinken, HTTP status codes

This commit is contained in:
jgoel 2020-10-04 18:35:45 -04:00
parent 2c71feb998
commit e932be7d92
2 changed files with 6 additions and 10 deletions

View file

@ -46,12 +46,12 @@ def recipe():
try:
recipe = scrape_recipe(url)
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)
except:
logging.exception(url)
return render_template('parse_error.html', domain=domain)
return render_template('parse_error.html', domain=domain), 418
@app.route('/supported-websites')
def supported_websites():

View file

@ -10,8 +10,8 @@ class EssenUndTrinken(Recipe):
recipe['name'] = d['name']
recipe['description'] = d.get('description', '')
recipe['ingredients'] = d['recipeIngredient']
recipe['instructions'] = self.cleanhtml(d['recipeInstructions']).split('\n')
recipe['image'] = d['image']
recipe['instructions'] = d['recipeInstructions']
recipe['image'] = d['image'][0]['url']
return recipe
@ -24,13 +24,9 @@ class EssenUndTrinken(Recipe):
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)
recipe.update(parsed_recipe)
return recipe
def cleanhtml(self, txt):
cleanr = re.compile('<.*?>')
return re.sub(cleanr, '', txt.lstrip(" \n"))
return recipe