From 3b32b14f44476f2b4a450f7226523321e69c0c08 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 4 Sep 2023 13:12:14 +0300 Subject: Improve DigestPlugin --- app/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/utils.py') diff --git a/app/utils.py b/app/utils.py index 77ea775..626ee24 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,4 +1,4 @@ -import time +from datetime import datetime from typing import TypeAlias, Union from app.Item import Item from dataclasses import asdict @@ -17,9 +17,11 @@ def get_param(key: str, params: Params) -> str: def item_to_dict(item: Item) -> ItemDict: - return asdict(item) + d = asdict(item) + d["pub_date"] = datetime.isoformat(d["pub_date"]) if d["pub_date"] else None + return d def dict_to_item(d: ItemDict) -> Item: pub_date, rest = (lambda pub_date, **rest: (pub_date, rest))(**d) # type: ignore - return Item(pub_date=time.struct_time(pub_date), **rest) # type: ignore + return Item(pub_date=datetime.fromisoformat(pub_date), **rest) # type: ignore -- cgit v1.3