diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-04 13:12:14 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | 3b32b14f44476f2b4a450f7226523321e69c0c08 (patch) | |
| tree | cfb93d411ce7938f03403790abffbd1c4d04ed54 /plugins/FeedSourcePlugin.py | |
| parent | 70607eeb1fc4d3fb259ad7a9c07cb26afe1493cd (diff) | |
Improve DigestPlugin
Diffstat (limited to 'plugins/FeedSourcePlugin.py')
| -rw-r--r-- | plugins/FeedSourcePlugin.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/plugins/FeedSourcePlugin.py b/plugins/FeedSourcePlugin.py index 575e5d6..e271092 100644 --- a/plugins/FeedSourcePlugin.py +++ b/plugins/FeedSourcePlugin.py @@ -1,10 +1,19 @@ import feedparser # type: ignore +import time +from datetime import datetime, timezone from typing import Any from app.Item import Item, ItemEnclosure from app.PluginInterface import Params, PluginInterface from app.utils import ItemDict, get_param +def struct_time_to_utc_datetime(struct_time: time.struct_time) -> datetime: + timestamp = time.mktime(struct_time) + naive_datetime = datetime.fromtimestamp(timestamp) + aware_datetime = naive_datetime.replace(tzinfo=timezone.utc) + return aware_datetime + + class Plugin(PluginInterface): def __init__(self, id: str, params: Params) -> None: super().__init__(id, params) @@ -39,16 +48,25 @@ class Plugin(PluginInterface): ) ) + datetime_1970: datetime = datetime.fromtimestamp(0) + published_time_struct: Any = d["published_parsed"] + published_datetime = ( + struct_time_to_utc_datetime(published_time_struct) + if published_time_struct + else datetime_1970 + ) + result_items.append( Item( title=d.get("title", None), # type: ignore - link=d.get("link", None), # type: ignore + link=d["link"], # type: ignore description=d.get("description", None), # type: ignore author=d.get("author", None), # type: ignore - pub_date=d.get("published_parsed", None), # type: ignore + pub_date=published_datetime, category=d.get("category", None), # type: ignore comments=d.get("comments"), # type: ignore enclosures=item_enclosures, + guid=d["link"], # type: ignore ) ) |
