Skip to content

Commit

Permalink
auto add schema attrs in json importer
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jun 26, 2023
1 parent 6acd892 commit cc64717
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,12 @@ def recipe_from_source(request):
}, status=status.HTTP_400_BAD_REQUEST)
else:
try:
json.loads(data)
data = "<script type='application/ld+json'>" + data + "</script>"
data_json = json.loads(data)
if '@context' not in data_json:
data_json['@context'] = 'https://schema.org'
if '@type' not in data_json:
data_json['@type'] = 'Recipe'
data = "<script type='application/ld+json'>" + json.dumps(data_json) + "</script>"
except JSONDecodeError:
pass
scrape = text_scraper(text=data, url=url)
Expand Down

0 comments on commit cc64717

Please sign in to comment.