diff --git a/qtribu/gui/dlg_contents.py b/qtribu/gui/dlg_contents.py index 8ba5b898..45b66621 100644 --- a/qtribu/gui/dlg_contents.py +++ b/qtribu/gui/dlg_contents.py @@ -104,6 +104,12 @@ def donate(self) -> None: open_url_in_browser("https://geotribu.fr/team/sponsoring/") def refresh_list(self, query_action: Callable[[], str]) -> None: + """ + Refresh content list as well as treewidget that list all contents + + :param query_action: action to call for potentially filtering contents + :type query_action: Callable[[], str] + """ # fetch last RSS items using JSONFeed rss_contents = self.json_feed_client.fetch(query=query_action()) years = sorted(set([c.date_pub.year for c in rss_contents]), reverse=True) @@ -129,6 +135,15 @@ def refresh_list(self, query_action: Callable[[], str]) -> None: @QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem, int) def on_tree_view_item_click(self, item: QTreeWidgetItem, column: int): + """ + Method called when a content item is clicked + + :param item: item that is clicked by user + :type item: QTreeWidgetItem + :param column: column that is clicked by user + :type column: int + """ + # TODO print(item, column, item.text(column)) def on_search_text_changed(self) -> None: @@ -151,7 +166,10 @@ def on_category_changed(self, value: str) -> None: @staticmethod def _build_tree_widget_item_from_content(content: RssItem) -> QTreeWidgetItem: """ - Builds a QTreeWidgetItem from a RSS content + Builds a QTreeWidgetItem from a RSS content item + + :param content: content to generate item for + :type content: RssItem """ item = QTreeWidgetItem( [ diff --git a/qtribu/logic/json_feed.py b/qtribu/logic/json_feed.py index 29267ce3..772e5e75 100644 --- a/qtribu/logic/json_feed.py +++ b/qtribu/logic/json_feed.py @@ -17,6 +17,10 @@ class JsonFeedClient: + """ + Class representing a Geotribu's JSON feed client + """ + items: Optional[List[RssItem]] = None last_fetch_date: Optional[datetime] = None @@ -28,6 +32,14 @@ def __init__( self.url = url def fetch(self, query: str = "") -> list[RssItem]: + """ + Fetch RSS feed items using JSON Feed + + :param query: filter to look for items matching this query + :type query: str + + :return: list of RssItem objects matching the query filter + """ if not self.items or ( self.last_fetch_date and (datetime.now() - self.last_fetch_date).total_seconds() @@ -40,6 +52,11 @@ def fetch(self, query: str = "") -> list[RssItem]: return [i for i in self.items if self._matches(query, i)] def categories(self) -> list[str]: + """ + Get a list of all categories available in the RSS feed + + :return: list of categories available in the RSS feed + """ tags = [] for content in self.fetch(): tags.extend([c.lower() for c in content.categories]) @@ -47,6 +64,14 @@ def categories(self) -> list[str]: @staticmethod def _map_item(item: dict[str, Any]) -> RssItem: + """ + Map raw JSON object coming from JSON feed to an RssItem object + + :param item: raw JSON object + :type item: dict[str, Any] + + :return: RssItem + """ return RssItem( abstract=item.get("content_html"), author=[i["name"] for i in item.get("authors")], @@ -62,7 +87,16 @@ def _map_item(item: dict[str, Any]) -> RssItem: @staticmethod def _matches(query: str, item: RssItem) -> bool: - """Moteur de recherche du turfu""" + """ + Check if item matches given query + + :param query: filter to look for items matching this query + :type query: str + :param item: RssItem to check + :type item: RssItem + + :return: True if item matches given query, False if not + """ words = query.split(" ") if len(words) > 1: return all([JsonFeedClient._matches(w, item) for w in words])