diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-03 17:56:52 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | e05dfe63724ae4aa4845c6fb5e7f8d5aa0974e16 (patch) | |
| tree | 82645f76eb9dd23f57fa4d57c43d21116a6bbea0 /app/utils.py | |
| parent | faf43ba175a747644578f4f1ce02c38e87d23d34 (diff) | |
Implement RSS spec stuff
Diffstat (limited to 'app/utils.py')
| -rw-r--r-- | app/utils.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/utils.py b/app/utils.py index 824d370..77ea775 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,17 +1,25 @@ +import time +from typing import TypeAlias, Union from app.Item import Item from dataclasses import asdict +from app.PluginInterface import Params -def get_param(key: str, params: dict[str, str]) -> str: +ItemDictValue: TypeAlias = Union[str, dict[str, "ItemDictValue"], list["ItemDictValue"]] +ItemDict: TypeAlias = dict[str, ItemDictValue] + + +def get_param(key: str, params: Params) -> str: if key not in params: raise Exception(f"no {key} field in config entry: " + str(params)) return params[key] -def item_to_dict(item: Item) -> dict[str, str]: +def item_to_dict(item: Item) -> ItemDict: return asdict(item) -def dict_to_item(d: dict[str, str]) -> Item: - return Item(**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 |
