From fdb01d72cbd4c5aafea32eca517dbf9ef7bbc62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Wed, 1 May 2024 10:02:10 +0200 Subject: Configure and run ruff (check & format) --- rss.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'rss.py') diff --git a/rss.py b/rss.py index 8625c73..ccf0cb5 100755 --- a/rss.py +++ b/rss.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 +from dataclasses import dataclass from datetime import datetime -from typing import List def _format_date(dt): @@ -50,20 +50,22 @@ def _format_date(dt): ) +@dataclass class RSSItem: title: str url: str content: str date: str - enclosures: List[str] + enclosures: list[str] guid: str +@dataclass class RSSFeed: title: str url: str description: str - content: List[RSSItem] + content: list[RSSItem] def escape(str): @@ -84,27 +86,25 @@ def buildRSS(feed_data: RSSFeed): feed = f""" - {feed_data['title']} - {feed_data['url']} - {escape(feed_data['description'])} + {feed_data.title} + {feed_data.url} + {escape(feed_data.description)} {_format_date(datetime.now())}""" - for item in feed_data["content"]: + for item in feed_data.content: feed += " " - feed += f" <![CDATA[{item.get('title', 'N/A')}]]>" - feed += f" {item.get('url', 'N/A')}" - feed += ( - f" " - ) - if "date" in item: - if type(item["date"]) is str: - feed += f" {item['date']}" + feed += f" <![CDATA[{item.title or 'N/A'}]]>" + feed += f" {item.url or 'N/A'}" + feed += f" " + if item.date: + if isinstance(item.date, str): + feed += f" {item.date}" else: - feed += f" {_format_date(item['date'])}" - for enclosure in item.get("enclosures", []): + feed += f" {_format_date(item.date)}" + for enclosure in item.enclosures: feed += f' ' - if "guid" in item: - feed += f" {item['guid']}" + if item.guid: + feed += f" {item.guid}" feed += " " feed += " " -- cgit v1.2.3