From a0e5919236753819c10e1aea096806cc894054d0 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Sat, 30 Jan 2021 15:25:38 +0100 Subject: [PATCH] moved the refreshlogic out of podcast --- python/podcast/podcast.py | 13 +++------- python/podcast/podcastlist.py | 14 ++++++++--- qml/components/FeedParser.py | 39 +++++++++++++---------------- qml/components/FeedParserPython.qml | 4 +-- qml/pages/Archive.qml | 2 +- qml/pages/Inbox.qml | 2 +- qml/pages/Queue.qml | 2 +- 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/python/podcast/podcast.py b/python/podcast/podcast.py index 424d634..1f2570d 100644 --- a/python/podcast/podcast.py +++ b/python/podcast/podcast.py @@ -306,6 +306,7 @@ class Podcast: def refresh(self, moveto, limit=0): """ Refresh podcast and return list of new entries + @type moveto: int the page the podcast should be moved to (see FeedParser#movePost) """ pyotherside.send("refreshPost", self.title) old_published = self.published @@ -326,7 +327,8 @@ class Podcast: logger.debug("Moveto is %d", move) - yield from self.__process_refreshed_feedentries(feed, limit, move) + for post in self.__process_refreshed_feedentries(feed, limit, move): + yield (move,post) except NotModified: logger.info("Got 304 response, skipping") pyotherside.send("refreshPost", None) @@ -337,14 +339,7 @@ class Podcast: yields all new entries """ new_posts = self.__process_episodes(feed, limit) - for post in new_posts: - yield { - "id": post.id, - "post": post.get_data(), - "pctitle": self.title, - "pstitle": post.title, - "move": move - } + yield from new_posts logger.info("Fount %d new entries.", len(new_posts)) def set_params(self, params): diff --git a/python/podcast/podcastlist.py b/python/podcast/podcastlist.py index 5fe15d6..4ae86d7 100644 --- a/python/podcast/podcastlist.py +++ b/python/podcast/podcastlist.py @@ -3,7 +3,7 @@ List of subscribed podcasts """ import sys -from typing import List +from typing import List, Tuple, Iterator sys.path.append("../") @@ -73,9 +73,10 @@ class PodcastList: if hasattr(pc, "subscribed") and pc.subscribed: yield podcast - def refresh(self, moveto, limit=0): + def refresh(self, moveto, limit=0) -> Iterator[Tuple[object, str, str, int]]: """ Refresh all podcasts and put them in queue, index, or archive + @rtype: Iterator[Tuple[object, str, str, int]], yields the postid, podcastitle, posttitle, move """ pllen = len(self.podcasts) @@ -85,8 +86,13 @@ class PodcastList: if pc: try: if pc.subscribed: - for post in pc.refresh(moveto, limit): - yield post + for move, post in pc.refresh(moveto, limit): + yield ( + post.id, + podcast.title, + post.title, + move + ) except: logger.exception( "podcast refresh failed for %s." % pc.title diff --git a/qml/components/FeedParser.py b/qml/components/FeedParser.py index 39984ae..53e6be6 100644 --- a/qml/components/FeedParser.py +++ b/qml/components/FeedParser.py @@ -114,24 +114,24 @@ def delete_podcast(url): get_podcasts() -def movePost(post): +def movePost(move: int, postid): """ Do move the object into the right place Returns page for Notification """ page = "Inbox" - if post["move"] == 0: - InboxFactory().get_inbox().insert(post["id"]) + if move == 0: + InboxFactory().get_inbox().insert(postid) page = "Inbox" - elif post["move"] == 1: - QueueFactory().get_queue().insert_next(post["id"]) + elif move == 1: + QueueFactory().get_queue().insert_next(postid) page = "Queue" - elif post["move"] == 2: - QueueFactory().get_queue().insert_bottom(post["id"]) + elif move == 2: + QueueFactory().get_queue().insert_bottom(postid) page = "Queue" - elif post["move"] == 3: - ArchiveFactory().get_archive().insert(post["id"]) + elif move == 3: + ArchiveFactory().get_archive().insert(postid) page = "History" return page @@ -157,14 +157,14 @@ def refresh_podcast(url, moveto, download, limit=0): podcast = PodcastFactory().get_podcast(url) posts = [] - for post in podcast.refresh(moveto, limit): - page = movePost(post) - posts.append(post["id"]) + for move, post in podcast.refresh(moveto, limit): + page = movePost(move, post.id) + posts.append(post.id) pyotherside.send( - "updatesNotification", post["pctitle"], post["pstitle"], page + "updatesNotification", podcast.title, post.title, page ) - pyotherside.send("newPodcasts", posts) + pyotherside.send("refreshFinished") def refresh_podcasts(moveto, download, limit=0): @@ -177,17 +177,14 @@ def refresh_podcasts(moveto, download, limit=0): podcast_list = PodcastListFactory().get_podcast_list() - posts = [] - - for post in podcast_list.refresh(moveto, limit): - page = movePost(post) - posts.append(post["id"]) + for postid, podcasttitle, posttitle, move in podcast_list.refresh(moveto, limit): + page = movePost(move, postid) pyotherside.send( - "updatesNotification", post["pctitle"], post["pstitle"], page + "updatesNotification", podcasttitle, posttitle, page ) # pyotherside.send("refreshProgress", count / pllen) - pyotherside.send("newPodcasts", posts) + pyotherside.send("refreshFinished") def get_podcast_params(url): diff --git a/qml/components/FeedParserPython.qml b/qml/components/FeedParserPython.qml index 46b7782..1e81620 100644 --- a/qml/components/FeedParserPython.qml +++ b/qml/components/FeedParserPython.qml @@ -13,7 +13,7 @@ Python { signal podcastParams(var pcdata) signal subscribed(string pcurl) signal updatesNotification(string pctitle, string pstitle, string page) - signal newPodcasts(var posts) + signal refreshFinished() signal htmlfile(string htmlfile) signal refreshProgress(real progress) signal refreshPost(string posttitle) @@ -31,7 +31,7 @@ Python { setHandler("podcastParams", podcastParams) setHandler("subscribed", subscribed) setHandler("updatesNotification", updatesNotification) - setHandler("newPodcasts", newPodcasts) + setHandler("refreshFinished", refreshFinished) setHandler("htmlfile", htmlfile) setHandler("refreshProgress", refreshProgress) setHandler("refreshPost", refreshPost) diff --git a/qml/pages/Archive.qml b/qml/pages/Archive.qml index 1f957b5..bc189b2 100644 --- a/qml/pages/Archive.qml +++ b/qml/pages/Archive.qml @@ -64,7 +64,7 @@ Page { Connections { target: feedparserhandler - onNewPodcasts: { + onRefreshFinished: { archivetitle.refreshing = false } onRefreshProgress: { diff --git a/qml/pages/Inbox.qml b/qml/pages/Inbox.qml index 0fa4cbb..a4f5c80 100644 --- a/qml/pages/Inbox.qml +++ b/qml/pages/Inbox.qml @@ -38,7 +38,7 @@ Page { Connections { target: feedparserhandler - onNewPodcasts: { + onRefreshFinished: { inboxhandler.getInboxEntries(podqast.ifilter) inboxhandler.getInboxPodData() } diff --git a/qml/pages/Queue.qml b/qml/pages/Queue.qml index 1965590..b12571c 100644 --- a/qml/pages/Queue.qml +++ b/qml/pages/Queue.qml @@ -41,7 +41,7 @@ Page { Connections { target: feedparserhandler - onNewPodcasts: { + onRefreshFinished: { queuehandler.getQueueEntries() } } -- GitLab