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:
ducklet 2020-12-16 15:52:05 +01:00
parent 9f6960babb
commit 22d9b33ce7

View file

@ -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=(