url import bug fixes
This commit is contained in:
parent
436a070730
commit
393aba1f31
@ -84,12 +84,17 @@ def get_recipe_from_source(text, url, space):
|
|||||||
for el in soup.find_all('script', type='application/ld+json'):
|
for el in soup.find_all('script', type='application/ld+json'):
|
||||||
el = remove_graph(el)
|
el = remove_graph(el)
|
||||||
if type(el) == list:
|
if type(el) == list:
|
||||||
for l in el:
|
for le in el:
|
||||||
parse_list.append(l)
|
parse_list.append(le)
|
||||||
else:
|
elif type(el) == dict:
|
||||||
parse_list.append(el)
|
parse_list.append(el)
|
||||||
for el in soup.find_all(type='application/json'):
|
for el in soup.find_all(type='application/json'):
|
||||||
parse_list.append(remove_graph(el))
|
el = remove_graph(el)
|
||||||
|
if type(el) == list:
|
||||||
|
for le in el:
|
||||||
|
parse_list.append(le)
|
||||||
|
elif type(el) == dict:
|
||||||
|
parse_list.append(el)
|
||||||
|
|
||||||
# if a url was not provided, try to find one in the first document
|
# if a url was not provided, try to find one in the first document
|
||||||
if not url and len(parse_list) > 0:
|
if not url and len(parse_list) > 0:
|
||||||
@ -182,10 +187,10 @@ def remove_graph(el):
|
|||||||
if isinstance(el, Tag):
|
if isinstance(el, Tag):
|
||||||
try:
|
try:
|
||||||
el = json.loads(el.string)
|
el = json.loads(el.string)
|
||||||
|
if '@graph' in el:
|
||||||
|
for x in el['@graph']:
|
||||||
|
if '@type' in x and x['@type'] == 'Recipe':
|
||||||
|
el = x
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
if '@graph' in el:
|
|
||||||
for x in el['@graph']:
|
|
||||||
if '@type' in x and x['@type'] == 'Recipe':
|
|
||||||
el = x
|
|
||||||
return el
|
return el
|
||||||
|
@ -284,7 +284,7 @@ def parse_keywords(keyword_json, space):
|
|||||||
for kw in keyword_json:
|
for kw in keyword_json:
|
||||||
kw = normalize_string(kw)
|
kw = normalize_string(kw)
|
||||||
if k := Keyword.objects.filter(name=kw, space=space).first():
|
if k := Keyword.objects.filter(name=kw, space=space).first():
|
||||||
if len (k['text']) > 0:
|
if len(k) != 0:
|
||||||
keywords.append({'id': str(k.id), 'text': str(k)})
|
keywords.append({'id': str(k.id), 'text': str(k)})
|
||||||
else:
|
else:
|
||||||
keywords.append({'id': random.randrange(1111111, 9999999, 1), 'text': kw})
|
keywords.append({'id': random.randrange(1111111, 9999999, 1), 'text': kw})
|
||||||
|
Loading…
Reference in New Issue
Block a user