urlinfo:generic: fix name retrival from jsonld things
For some sites a list of persons is just a list of strings, not proper Person typed objects.
This commit is contained in:
parent
9f6960babb
commit
22d9b33ce7
1 changed files with 9 additions and 1 deletions
|
|
@ -165,6 +165,14 @@ def fromisoformat(s) -> datetime:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
def name_from_thing(p: Union[Mapping, str]) -> Optional[str]:
|
||||||
|
if type(p) is str:
|
||||||
|
return p
|
||||||
|
# if p["@type"] == "Person":
|
||||||
|
# return p["name"]
|
||||||
|
return p.get("name")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LinkedData:
|
class LinkedData:
|
||||||
title: Optional[str]
|
title: Optional[str]
|
||||||
|
|
@ -181,7 +189,7 @@ class LinkedData:
|
||||||
creators = []
|
creators = []
|
||||||
for k in "director", "creator", "author", "producer", "contributor":
|
for k in "director", "creator", "author", "producer", "contributor":
|
||||||
if k in o:
|
if k in o:
|
||||||
creators += [p["name"] for p in aslist(o[k]) if p["@type"] == "Person"]
|
creators += [name for p in aslist(o[k]) if (name := name_from_thing(p))]
|
||||||
return cls(
|
return cls(
|
||||||
title=o.get("headline") or o.get("name"),
|
title=o.get("headline") or o.get("name"),
|
||||||
published=(
|
published=(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue