summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Glüpker <git@wgmd.de>2024-05-01 10:02:10 +0200
committerAndré Glüpker <git@wgmd.de>2024-05-01 10:04:51 +0200
commitfdb01d72cbd4c5aafea32eca517dbf9ef7bbc62d (patch)
tree6f2213e91be3ea8ef09402d9f1d18cc4816e966c
parent9e75b5cb4b64e1fe430ce3720dbe3f80988d8435 (diff)
downloadrss-feeds-fdb01d72cbd4c5aafea32eca517dbf9ef7bbc62d.tar.gz
rss-feeds-fdb01d72cbd4c5aafea32eca517dbf9ef7bbc62d.tar.bz2
rss-feeds-fdb01d72cbd4c5aafea32eca517dbf9ef7bbc62d.zip
Configure and run ruff (check & format)
-rw-r--r--poetry.lock28
-rw-r--r--pyproject.toml41
-rwxr-xr-xrss.py38
-rwxr-xr-xwebapp.py1
-rwxr-xr-xwsgi.py2
5 files changed, 89 insertions, 21 deletions
diff --git a/poetry.lock b/poetry.lock
index 3319354..3718bcf 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -142,6 +142,32 @@ files = [
]
[[package]]
+name = "ruff"
+version = "0.4.2"
+description = "An extremely fast Python linter and code formatter, written in Rust."
+optional = false
+python-versions = ">=3.7"
+files = [
+ {file = "ruff-0.4.2-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:8d14dc8953f8af7e003a485ef560bbefa5f8cc1ad994eebb5b12136049bbccc5"},
+ {file = "ruff-0.4.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:24016ed18db3dc9786af103ff49c03bdf408ea253f3cb9e3638f39ac9cf2d483"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0e2e06459042ac841ed510196c350ba35a9b24a643e23db60d79b2db92af0c2b"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3afabaf7ba8e9c485a14ad8f4122feff6b2b93cc53cd4dad2fd24ae35112d5c5"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:799eb468ea6bc54b95527143a4ceaf970d5aa3613050c6cff54c85fda3fde480"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ec4ba9436a51527fb6931a8839af4c36a5481f8c19e8f5e42c2f7ad3a49f5069"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6a2243f8f434e487c2a010c7252150b1fdf019035130f41b77626f5655c9ca22"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8772130a063f3eebdf7095da00c0b9898bd1774c43b336272c3e98667d4fb8fa"},
+ {file = "ruff-0.4.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6ab165ef5d72392b4ebb85a8b0fbd321f69832a632e07a74794c0e598e7a8376"},
+ {file = "ruff-0.4.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:1f32cadf44c2020e75e0c56c3408ed1d32c024766bd41aedef92aa3ca28eef68"},
+ {file = "ruff-0.4.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:22e306bf15e09af45ca812bc42fa59b628646fa7c26072555f278994890bc7ac"},
+ {file = "ruff-0.4.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:82986bb77ad83a1719c90b9528a9dd663c9206f7c0ab69282af8223566a0c34e"},
+ {file = "ruff-0.4.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:652e4ba553e421a6dc2a6d4868bc3b3881311702633eb3672f9f244ded8908cd"},
+ {file = "ruff-0.4.2-py3-none-win32.whl", hash = "sha256:7891ee376770ac094da3ad40c116258a381b86c7352552788377c6eb16d784fe"},
+ {file = "ruff-0.4.2-py3-none-win_amd64.whl", hash = "sha256:5ec481661fb2fd88a5d6cf1f83403d388ec90f9daaa36e40e2c003de66751798"},
+ {file = "ruff-0.4.2-py3-none-win_arm64.whl", hash = "sha256:cbd1e87c71bca14792948c4ccb51ee61c3296e164019d2d484f3eaa2d360dfaf"},
+ {file = "ruff-0.4.2.tar.gz", hash = "sha256:33bcc160aee2520664bc0859cfeaebc84bb7323becff3f303b8f1f2d81cb4edc"},
+]
+
+[[package]]
name = "soupsieve"
version = "2.1"
description = "A modern CSS selector implementation for Beautiful Soup."
@@ -170,4 +196,4 @@ watchdog = ["watchdog"]
[metadata]
lock-version = "2.0"
python-versions = ">=3.9,<4"
-content-hash = "0a32dab5b53b84b5f71fe372f3a511b004eca3899c35c7440937ee8fa25de826"
+content-hash = "7fd5016ff10dd425a4e619e2446787464d118fadc689587621ccb0d5e9b1ffb6"
diff --git a/pyproject.toml b/pyproject.toml
index 8714012..dbdfe88 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,6 +10,47 @@ Flask = "1.1.2"
beautifulsoup4 = "4.9.3"
[tool.poetry.group.dev.dependencies]
+ruff = "0.4.2"
+
+[tool.ruff]
+line-length = 120
+
+target-version = "py39" # wgmd.de server version
+
+lint.select = [
+ # Pyflakes
+ "F",
+ # Pycodestyle
+ "E",
+ "W",
+ # flake8-bugbear
+ "B",
+ "C",
+ # flake8-comprehensions
+ "C4",
+ # flake8-implicit-str-concat
+ "ISC",
+ # isort
+ "I",
+ # mccabe (complexity)
+ "C901",
+ # pyupgrade / python features for selected version
+ "UP",
+ # flake8-pytest-style
+ "PT",
+ # flake8-simplify
+ "SIM",
+ # flake8-print
+ "T20",
+ # pylint
+ "PLC", "PLE", "PLR", "PLW",
+ # Ruff specific
+ "RUF",
+]
+
+lint.ignore = [
+ "ISC001", # causes issues with formatter
+]
[build-system]
requires = ["poetry-core>=1.7.0"]
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"""<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
- <title>{feed_data['title']}</title>
- <link>{feed_data['url']}</link>
- <description>{escape(feed_data['description'])}</description>
+ <title>{feed_data.title}</title>
+ <link>{feed_data.url}</link>
+ <description>{escape(feed_data.description)}</description>
<lastBuildDate>{_format_date(datetime.now())}</lastBuildDate>"""
- for item in feed_data["content"]:
+ for item in feed_data.content:
feed += " <item>"
- feed += f" <title><![CDATA[{item.get('title', 'N/A')}]]></title>"
- feed += f" <link>{item.get('url', 'N/A')}</link>"
- feed += (
- f" <description><![CDATA[{item.get('content', 'N/A')}]]></description>"
- )
- if "date" in item:
- if type(item["date"]) is str:
- feed += f" <pubDate>{item['date']}</pubDate>"
+ feed += f" <title><![CDATA[{item.title or 'N/A'}]]></title>"
+ feed += f" <link>{item.url or 'N/A'}</link>"
+ feed += f" <description><![CDATA[{item.content or 'N/A'}]]></description>"
+ if item.date:
+ if isinstance(item.date, str):
+ feed += f" <pubDate>{item.date}</pubDate>"
else:
- feed += f" <pubDate>{_format_date(item['date'])}</pubDate>"
- for enclosure in item.get("enclosures", []):
+ feed += f" <pubDate>{_format_date(item.date)}</pubDate>"
+ for enclosure in item.enclosures:
feed += f' <media:content url="{enclosure}" />'
- if "guid" in item:
- feed += f" <guid>{item['guid']}</guid>"
+ if item.guid:
+ feed += f" <guid>{item.guid}</guid>"
feed += " </item>"
feed += " </channel>"
diff --git a/webapp.py b/webapp.py
index 66acbb1..cd68396 100755
--- a/webapp.py
+++ b/webapp.py
@@ -3,6 +3,7 @@
import logging
from flask import Flask, Response
+
from rss import buildRSS
from zdf import zdf
diff --git a/wsgi.py b/wsgi.py
index 90d4782..4a800b0 100755
--- a/wsgi.py
+++ b/wsgi.py
@@ -4,4 +4,4 @@ import sys
sys.path.append("./")
-from webapp import app as application
+from webapp import app as application # noqa: F401