Skip to content

Commit

Permalink
Merge pull request #188 from geotribu/refactor/sanitize-rss-reader
Browse files Browse the repository at this point in the history
refactor(rss): move RSS reader to its own folder
  • Loading branch information
Guts authored Aug 5, 2024
2 parents c9e6fe7 + d5eb120 commit 9bba760
Show file tree
Hide file tree
Showing 16 changed files with 554 additions and 358 deletions.
6 changes: 3 additions & 3 deletions qtribu/gui/dlg_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from qtribu.constants import ICON_ARTICLE, ICON_GEORDP
from qtribu.gui.form_article import ArticleForm
from qtribu.gui.form_rdp_news import RdpNewsForm
from qtribu.logic import RssItem
from qtribu.logic.json_feed import JsonFeedClient
from qtribu.logic.news_feed.json_feed import JsonFeedClient
from qtribu.logic.news_feed.mdl_rss_item import RssItem
from qtribu.toolbelt import PlgLogger, PlgOptionsManager
from qtribu.toolbelt.commons import open_url_in_browser, open_url_in_webviewer

Expand Down Expand Up @@ -257,7 +257,7 @@ def _build_tree_widget_item_from_content(content: RssItem) -> QTreeWidgetItem:
[
content.date_pub.strftime("%d %B"),
content.title,
", ".join(content.author),
", ".join(content.authors),
tags,
content.url,
]
Expand Down
2 changes: 0 additions & 2 deletions qtribu/logic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#! python3 # noqa: E265
from .custom_datatypes import RssItem # noqa: F401
from .rss_reader import RssMiniReader # noqa: F401
from .splash_changer import SplashChanger # noqa: F401
22 changes: 0 additions & 22 deletions qtribu/logic/custom_datatypes.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# plugin
from qtribu.__about__ import __title__, __version__
from qtribu.logic import RssItem
from qtribu.logic.news_feed.mdl_rss_item import RssItem
from qtribu.toolbelt import NetworkRequestsManager, PlgLogger, PlgOptionsManager

# -- GLOBALS --
Expand All @@ -30,7 +30,7 @@
FETCH_UPDATE_INTERVAL_SECONDS = 7200


## -- CLASSES --
# -- CLASSES --


class JsonFeedClient:
Expand Down Expand Up @@ -89,7 +89,7 @@ def authors(self) -> list[str]:
"""
authors = []
for content in self.fetch():
for ca in content.author:
for ca in content.authors:
authors.append(" ".join([a.title() for a in ca.split(" ")]))
return sorted(set(authors))

Expand All @@ -115,7 +115,7 @@ def _map_item(item: dict[str, Any]) -> RssItem:
"""
return RssItem(
abstract=item.get("content_html"),
author=[i["name"] for i in item.get("authors")],
authors=[i["name"] for i in item.get("authors")],
categories=item.get("tags", []),
date_pub=datetime.fromisoformat(item.get("date_published")),
guid=item.get("id"),
Expand All @@ -142,7 +142,7 @@ def _matches(query: str, item: RssItem) -> bool:
return all([JsonFeedClient._matches(w, item) for w in words])
return (
query.upper() in item.abstract.upper()
or query.upper() in ",".join(item.author).upper()
or query.upper() in ",".join(item.authors).upper()
or query.upper() in ",".join(item.categories).upper()
or query.upper() in item.date_pub.isoformat().upper()
or query.upper() in item.image_url.upper()
Expand Down
21 changes: 21 additions & 0 deletions qtribu/logic/news_feed/mdl_rss_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! python3 # noqa: E265

# Standard library
from dataclasses import dataclass
from typing import Optional


@dataclass
class RssItem:
"""Dataclass describing a RSS channel item."""

abstract: Optional[str] = None
authors: Optional[list[Optional[str]]] = None
categories: Optional[list[Optional[str]]] = None
date_pub: Optional[tuple[int, ...]] = None
guid: Optional[str] = None
image_length: Optional[str] = None
image_type: Optional[str] = None
image_url: Optional[str] = None
title: Optional[str] = None
url: Optional[str] = None
Loading

0 comments on commit 9bba760

Please sign in to comment.