urlinfo:generic: be more relaxed with datetime isoformat
This commit is contained in:
parent
e1533bb7e2
commit
124ed1cf25
1 changed files with 11 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import *
|
||||
|
||||
from ...functions import (
|
||||
|
|
@ -148,6 +148,15 @@ def aslist(o: Any):
|
|||
return o if type(o) is list else [o]
|
||||
|
||||
|
||||
def fromisoformat(s) -> datetime:
|
||||
try:
|
||||
datetime.fromisoformat(s)
|
||||
except ValueError:
|
||||
pass
|
||||
# '2003-08-15T13:18:27Z'
|
||||
return datetime.strptime(s, r"%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
|
||||
|
||||
|
||||
@dataclass
|
||||
class LinkedData:
|
||||
title: Optional[str]
|
||||
|
|
@ -168,9 +177,7 @@ class LinkedData:
|
|||
return cls(
|
||||
title=o.get("headline") or o.get("name"),
|
||||
published=(
|
||||
datetime.fromisoformat(o["datePublished"])
|
||||
if "datePublished" in o
|
||||
else None
|
||||
fromisoformat(o["datePublished"]) if "datePublished" in o else None
|
||||
),
|
||||
image=o.get("image") or o.get("logo"),
|
||||
description=o.get("description"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue