From af0641301b9371af1956506a3a9d043fa5b535e4 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Sat, 30 Jan 2021 16:37:03 +0100 Subject: [PATCH 1/6] moved the insert_date from podpost into archive --- python/podcast/archive.py | 39 +- python/podcast/data_migration.py | 28 +- qml/components/ArchiveHandler.py | 5 +- test/test_archive.py | 23 +- test/test_migration_to_v1.py | 3 +- test/test_podpost.py | 10 +- test/test_queue.py | 10 +- test/testdata/freakshow.rss | 5392 +----------------------------- 8 files changed, 86 insertions(+), 5424 deletions(-) diff --git a/python/podcast/archive.py b/python/podcast/archive.py index 0e2d649..ba5fa93 100644 --- a/python/podcast/archive.py +++ b/python/podcast/archive.py @@ -1,9 +1,10 @@ """ Archive of listened poposts """ - +import datetime import sys import time +from typing import List, Any sys.path.append("../") @@ -13,17 +14,30 @@ from podcast.factory import Factory archivename = "the_archive" +class ArchiveEntry: + insert_date: float + podpost: str + + @classmethod + def of_podpost(cls, postid: str): + archive_entry = ArchiveEntry() + archive_entry.podpost = postid + archive_entry.insert_date = time.time() + return archive_entry + + class Archive: """ The podcast Archive. It has a list of podposts """ + _archive_entries: list[ArchiveEntry] def __init__(self): """ Initialization """ - self.podposts = [] # Id list of posposts + self._archive_entries = [] # Id list of posposts def save(self): """ @@ -38,28 +52,27 @@ class Archive: Insert an podost """ - if podpost not in self.podposts: - self.podposts.insert(0, podpost) - post = Factory().get_podpost(podpost) - if post.insert_date == None: - post.insert_date = time.time() - post.save() + if podpost not in [e.podpost for e in self._archive_entries]: + self._archive_entries.insert(0, ArchiveEntry.of_podpost(podpost)) self.save() - def get_podposts(self): + def get_podposts(self, sorted_by_date=False): """ get the list of podposts """ - - for podpost in self.podposts: - yield podpost + if not sorted_by_date: + for archive_entry in self._archive_entries: + yield archive_entry.podpost + else: + for archive_entry in sorted(self._archive_entries, key=lambda e: e.insert_date, reverse=True): + yield archive_entry.podpost def remove_podpost(self, podpost): """ Remove a podpost from archive """ - self.podposts.remove(podpost) + self._archive_entries = [entry for entry in self._archive_entries if entry.podpost != podpost] class ArchiveFactory(metaclass=Singleton): diff --git a/python/podcast/data_migration.py b/python/podcast/data_migration.py index a7bcdbc..7fd6ccc 100644 --- a/python/podcast/data_migration.py +++ b/python/podcast/data_migration.py @@ -1,5 +1,7 @@ import logging import os +from typing import List + import pyotherside from podcast.factory import Factory @@ -41,10 +43,10 @@ def run_migrations(): migrate_podpost_v0_v1(Factory().get_podpost(entry_id)) i += 1 pyotherside.send("migrationProgress", i) + migrate_archive_v0_v1() set_versionnumber(1) pyotherside.send("migrationDone") - def get_versionnumber() -> int: versionfilepath = get_versionfile_path() if os.path.isfile(versionfilepath): @@ -64,6 +66,30 @@ def get_versionfile_path(): return os.path.join(Factory().data_home, "dataversion") +def migrate_archive_v0_v1(): + """ + migrates the id list to ArchiveEntry + """ + from podcast.archive import ArchiveFactory, ArchiveEntry, Archive + import datetime + archive: Archive = ArchiveFactory().get_archive() + if hasattr(archive, "podposts") and len(archive.podposts) > 0 and type(archive.podposts) is not ArchiveEntry: + old_archive: List[str] = archive.podposts + archive.__archive_entries = [] + for postid in old_archive: + archive_entry = ArchiveEntry() + post = Factory().get_podpost(postid) + if not post: + continue + if hasattr(post, "insert_date") and post.insert_date: + archive_entry.insert_date = post.insert_date + else: + archive_entry.insert_date = datetime.datetime.now() + archive_entry.podpost = postid + archive.__archive_entries.append(post) + del archive.podposts + + def migrate_podpost_v0_v1(self: Podpost): if hasattr(self, "entry"): if not hasattr(self, "isaudio"): diff --git a/qml/components/ArchiveHandler.py b/qml/components/ArchiveHandler.py index f488394..4a48d88 100644 --- a/qml/components/ArchiveHandler.py +++ b/qml/components/ArchiveHandler.py @@ -19,8 +19,8 @@ def get_archive_posts(podurl=None): entries = [] archive = ArchiveFactory().get_archive() - for post in archive.get_podposts(): - entry = Factory().get_podpost(post) + for archive_entry in archive.get_podposts(sorted_by_date=True): + entry = Factory().get_podpost(archive_entry.podpost) if podurl: if entry.podurl == podurl: entries.append(entry.get_data()) @@ -30,7 +30,6 @@ def get_archive_posts(podurl=None): else: pyotherside.send("ArchiveHandler: We have a none object") - entries.sort(key=lambda r: r["adate"], reverse=True) pyotherside.send("createArchiveList", entries) diff --git a/test/test_archive.py b/test/test_archive.py index e3d187d..a951a22 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -4,7 +4,6 @@ test the archive import sys -import httpretty from httpretty import HTTPretty, httprettified from test.test_podcast import read_testdata, xml_headers @@ -15,7 +14,6 @@ from podcast.archive import ArchiveFactory, Archive from podcast.factory import Factory from podcast.podcast import Podcast from podcast.podpost import Podpost -import podcast def test_create_archive(): """ @@ -43,18 +41,19 @@ def test_insert(): HTTPretty.register_uri(HTTPretty.GET, 'https://freakshow.fm/feed/opus/', body=read_testdata('testdata/freakshow.rss'), adding_headers=xml_headers) - a = ArchiveFactory().get_archive() - p = Podcast('https://freakshow.fm/feed/opus/') - e = p.get_entry(p.entry_ids_old_to_new[0]) - e.save() - a.insert(e.id) + archive = ArchiveFactory().get_archive() + podcast = Podcast('https://freakshow.fm/feed/opus/') + entry1 = podcast.get_entry(podcast.entry_ids_old_to_new[0]) + entry1.save() + archive.insert(entry1.id) - e2 = p.get_entry(p.entry_ids_old_to_new[1]) - e2.save() - a.insert(e2.id) + entry2 = podcast.get_entry(podcast.entry_ids_old_to_new[1]) + entry2.save() + archive.insert(entry2.id) - assert e.id in a.podposts - assert e2.id in a.podposts + result_posts = list(archive.get_podposts(sorted_by_date=True)) + assert entry1.id == result_posts[1] # older + assert entry2.id == result_posts[0] # newer def test_get_archives(): """ diff --git a/test/test_migration_to_v1.py b/test/test_migration_to_v1.py index 4f9e587..c694f0c 100644 --- a/test/test_migration_to_v1.py +++ b/test/test_migration_to_v1.py @@ -14,6 +14,7 @@ from podcast.queue import QueueFactory sys.path.append("../python") + def test_migration(): with tempfile.TemporaryDirectory() as tmpdir: copy_tree(os.path.join(os.path.dirname(__file__), "testdata/migrationtests_v1/"), tmpdir) @@ -23,7 +24,7 @@ def test_migration(): assert os.path.exists(os.path.join(tmpdir, "dataversion")) podcasts = list(PodcastListFactory().get_podcast_list().get_podcasts()) assert len(podcasts) == 1 - podcast:Podcast = PodcastFactory().get_podcast(podcasts[0]) + podcast: Podcast = PodcastFactory().get_podcast(podcasts[0]) assert podcast != None assert len(podcast.entry_ids_old_to_new) == 22 assert len(list(podcast.get_entries())) == 22 diff --git a/test/test_podpost.py b/test/test_podpost.py index 2d40f3c..b138568 100644 --- a/test/test_podpost.py +++ b/test/test_podpost.py @@ -3,17 +3,25 @@ Podpost tests """ import sys + +import httpretty +from httpretty import HTTPretty + +from test.test_podcast import read_testdata, xml_headers + sys.path.append("../python") from podcast.factory import Factory from podcast.podcast import Podcast from podcast.podpost import Podpost +@httpretty.activate def test_podpost_save(): """ Test podpost saving """ - + HTTPretty.register_uri(HTTPretty.GET, 'https://freakshow.fm/feed/opus/', + body=read_testdata('testdata/freakshow.rss'), adding_headers=xml_headers) f1 = Factory() p = Podcast('https://freakshow.fm/feed/opus/') diff --git a/test/test_queue.py b/test/test_queue.py index 7634336..0927ba5 100644 --- a/test/test_queue.py +++ b/test/test_queue.py @@ -4,6 +4,11 @@ test the queue import sys +import httpretty +from httpretty import HTTPretty + +from test.test_podcast import read_testdata, xml_headers + sys.path.append("../python") from podcast.queue import QueueFactory @@ -34,11 +39,12 @@ def test_queue_save(): q = QueueFactory().get_queue() q.save() - +@httpretty.activate def test_insert_top(): """ """ - + HTTPretty.register_uri(HTTPretty.GET, 'https://freakshow.fm/feed/opus/', + body=read_testdata('testdata/freakshow.rss'), adding_headers=xml_headers) q = QueueFactory().get_queue() l1 = len(q.podposts) p = Podcast('https://freakshow.fm/feed/opus/') diff --git a/test/testdata/freakshow.rss b/test/testdata/freakshow.rss index c81a8fc..e2b9ac7 100644 --- a/test/testdata/freakshow.rss +++ b/test/testdata/freakshow.rss @@ -56,5397 +56,7 @@ no no - - FS255 Bitcoin Recycling - https://freakshow.fm/fs255-bitcoin-recycling - Thu, 24 Dec 2020 18:02:10 +0000 - podlove-2020-12-24t16:44:11+00:00-2df73540be4775e - - - - 03:56:56 - Metaebene Personal Media - Tim Pritlove - Podcast Clients — 2020 Technik-Rückblick — LiDAR — iPhone 12 — M1 — OpenZFS — NAS — Mac Apps — Bildschirme - 255 - full - Das Jahr geht (endlich) zu Ende und wir füllen die Bits eines Bytes bis auf letzte Stelle. Ausgabe Nummer Zweihundertfünfundfünzig versucht Euch zu Weihnachten noch mal das Herz zu fluten. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Podcast Clients — 2020 Technik-Rückblick — LiDAR — iPhone 12 — M1 — OpenZFS — NAS — Mac Apps — Bildschirme

- -

Das Jahr geht (endlich) zu Ende und wir füllen die Bits eines Bytes bis auf letzte Stelle. Ausgabe Nummer Zweihundertfünfundfünzig versucht Euch zu Weihnachten noch mal das Herz zu fluten.

- -

Dauer: 3:56:56

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Denis Ahrens - - - roddi - -
- - FS254 Chat Roulette Business Edition - https://freakshow.fm/fs254-chat-roulette-business-edition - Thu, 10 Dec 2020 02:43:45 +0000 - podlove-2020-12-10t01:23:08+00:00-036a06860a74b9b - - - - 03:30:42 - Metaebene Personal Media - Tim Pritlove - Talking Heads — Konten und Banken — M1 und Wintel — Internet Tips — pretix — venueless — pretalx — Virtuelle Events — Videotechnik — Mikrofone und Headsets — Licht — Ethernet - 254 - full - Heute dreht sich alles um Events. Wir begrüßen rami als Gast in der Sendung, der das Projekt pretix losgetreten hat, dass ein Ticketing-System für Veranstaltungen aller Art ist. Wir sprechen über Online-Events und in was von der Pandemie-Zeit übrig bleiben wird, wenn wir uns wieder in der Realität treffen können. Dazu gibt es noch eine Reihe von Tips für Technik zur Durchführung von Audio- und Videosessions. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Talking Heads — Konten und Banken — M1 und Wintel — Internet Tips — pretix — venueless — pretalx — Virtuelle Events — Videotechnik — Mikrofone und Headsets — Licht — Ethernet

- -

Heute dreht sich alles um Events. Wir begrüßen rami als Gast in der Sendung, der das Projekt pretix losgetreten hat, dass ein Ticketing-System für Veranstaltungen aller Art ist. Wir sprechen über Online-Events und in was von der Pandemie-Zeit übrig bleiben wird, wenn wir uns wieder in der Realität treffen können. Dazu gibt es noch eine Reihe von Tips für Technik zur Durchführung von Audio- und Videosessions.

- -

Dauer: 3:30:42

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Letty - - - -Lettys Wunschliste Icon - - -
- -avatar - - -hukl - - - -Thomann Wishlist Icon - - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -rami - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Letty - - - hukl - - - rami - -
- - FS253 Zero Latency Computing - https://freakshow.fm/fs253-zero-latency-computing - Thu, 26 Nov 2020 23:00:32 +0000 - podlove-2020-11-26t22:43:23+00:00-130a4cec453a37f - - - - 03:41:53 - Metaebene Personal Media - Tim Pritlove - Ultraschall — M1 Macs — Big Sur - 253 - full - Nach zwei Wochen und vor allem nachdem manche von uns bereits ein paar der neuen M1 Macs erhalten habe dreht sich hier ein weiteres Mal alles um die neuen Computer. Wir teilen erste Erfahrungen und Einschätzungen und sind überhaupt sehr aufgeregt. Außerdem ist Ralf zu Gast und berichtet von den Fortschritten beim Ultraschall-Projekt. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Ultraschall — M1 Macs — Big Sur

- -

Nach zwei Wochen und vor allem nachdem manche von uns bereits ein paar der neuen M1 Macs erhalten habe dreht sich hier ein weiteres Mal alles um die neuen Computer. Wir teilen erste Erfahrungen und Einschätzungen und sind überhaupt sehr aufgeregt. Außerdem ist Ralf zu Gast und berichtet von den Fortschritten beim Ultraschall-Projekt.

- -

Dauer: 3:41:53

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Dominik Wagner - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Ralf Stockmann - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Dominik Wagner - - - Denis Ahrens - - - Ralf Stockmann - -
- - FS252 Keine grobe Feinheit - https://freakshow.fm/fs252-keine-grobe-feinheit - Thu, 12 Nov 2020 20:36:35 +0000 - podlove-2020-11-12t13:43:01+00:00-6312fbdf2ec0387 - - - - 03:50:53 - Metaebene Personal Media - Tim Pritlove - Kontowechsel — Pausenende — Elektrourlaub — Tesla Battery Day — iPhone 12 — Apple Watch — iOS 14 und AirPods Pro — Augmented Reality — Big Sur — ARM-Macs — 5G — Audio auf dem Mac — Audiointerfaces — Küchenkram - 252 - full - We are back. Nach einer längeren, im Kern ungeplanten aber trotzdem notwenidgen Verschnaufpause ist die Freak Show wieder am Start, denn wir mussten dringend mal wieder mehr über Macs reden. Wir gehen die neue Produkten von Apple der letzten Woche durch und natürlich legen wir einen Schwerpunkt auf die neuen ARM-Macs, die nun endlich vorgestellt worden. Dazu ein wenig Corona-Küchenkram rund um Waffeleisen und scharfe Messer. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Kontowechsel — Pausenende — Elektrourlaub — Tesla Battery Day — iPhone 12 — Apple Watch — iOS 14 und AirPods Pro — Augmented Reality — Big Sur — ARM-Macs — 5G — Audio auf dem Mac — Audiointerfaces — Küchenkram

- -

We are back. Nach einer längeren, im Kern ungeplanten aber trotzdem notwenidgen Verschnaufpause ist die Freak Show wieder am Start, denn wir mussten dringend mal wieder mehr über Macs reden. Wir gehen die neue Produkten von Apple der letzten Woche durch und natürlich legen wir einen Schwerpunkt auf die neuen ARM-Macs, die nun endlich vorgestellt worden. Dazu ein wenig Corona-Küchenkram rund um Waffeleisen und scharfe Messer.

- -

Dauer: 3:50:53

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -hukl - - - -Thomann Wishlist Icon - - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Dominik Wagner - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - hukl - - - Denis Ahrens - - - roddi - - - Dominik Wagner - -
- - FS251 Bürgermeisterladesäulen - https://freakshow.fm/fs251-buergermeisterladesaeulen - Sat, 18 Jul 2020 09:49:43 +0000 - podlove-2020-07-18t09:29:01+00:00-e6a090d7c680aed - - - - 03:19:11 - Metaebene Personal Media - Tim Pritlove - Eine Spezialausgabe der Freak Show mit dem Schwerpunkt Elektromobilität - 251 - full - Wir haben schon oft darüber gesprochen, aber so richtig Ahnung haben wir ja eh nicht. Deswegen haben wir (Roddi, Denis, Tim) uns den Philipp vom cleaneletric Podcast eingeladen um mal ganz ausführlich über den Stand der Dinge in Sachen Elektromobilität in Deutschland und dem Rest der Welt zu sprechen. Dabei versuchen wir zu ergründen, woran es noch hapert und wo vielleicht der Umstieg für viele schon näher liegt, als diese selbst noch glauben. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Eine Spezialausgabe der Freak Show mit dem Schwerpunkt Elektromobilität

- -

Wir haben schon oft darüber gesprochen, aber so richtig Ahnung haben wir ja eh nicht. Deswegen haben wir (Roddi, Denis, Tim) uns den Philipp vom cleaneletric Podcast eingeladen um mal ganz ausführlich über den Stand der Dinge in Sachen Elektromobilität in Deutschland und dem Rest der Welt zu sprechen. Dabei versuchen wir zu ergründen, woran es noch hapert und wo vielleicht der Umstieg für viele schon näher liegt, als diese selbst noch glauben.

- -

Dauer: 3:19:11

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Philipp Hellwig - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Denis Ahrens - - - roddi - - - Philipp Hellwig - -
- - FS250 Die Ente bleibt draußen - https://freakshow.fm/fs250-die-ente-bleibt-draussen - Thu, 02 Jul 2020 22:46:38 +0000 - podlove-2020-07-02t21:40:53+00:00-6b9d9aaa486e6bf - - - - 03:37:40 - Metaebene Personal Media - Tim Pritlove - Die 250. Sendung der Freak Show über die WWDC 2020 und andere Dinge - 250 - full - Nun sind schon über 12 Jahre vergangen seitdem die Freak Show (damals noch unter anderem Namen) ans Netz gegangen ist. Wir bedanken uns für die jahrelange Treue unserer Hörerinnen und Hörer, die mit ihrem Feedback immer dazu beigetragen haben, dass uns die Lust am Projekt nie vergangen ist. - -Heute sind wir dann auch standesgemäß vollzählig angetreten und dazu haben wir uns auch noch den Dominik dazugehört, um die Akustik für Euch komplett unübersichtlich zu gestalten. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Die 250. Sendung der Freak Show über die WWDC 2020 und andere Dinge

- -

Nun sind schon über 12 Jahre vergangen seitdem die Freak Show (damals noch unter anderem Namen) ans Netz gegangen ist. Wir bedanken uns für die jahrelange Treue unserer Hörerinnen und Hörer, die mit ihrem Feedback immer dazu beigetragen haben, dass uns die Lust am Projekt nie vergangen ist.
-
-Heute sind wir dann auch standesgemäß vollzählig angetreten und dazu haben wir uns auch noch den Dominik dazugehört, um die Akustik für Euch komplett unübersichtlich zu gestalten.

- -

Dauer: 3:37:40

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Dominik Wagner - -
- -avatar - - -hukl - - - -Thomann Wishlist Icon - - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Clemens Schrimpe - -
- -avatar - - -Letty - - - -Lettys Wunschliste Icon - - -
- -avatar - - -Tala - - - -Amazon Wishlist Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Dominik Wagner - - - hukl - - - Clemens Schrimpe - - - Letty - - - Tala - - - roddi - - - Denis Ahrens - -
- - FS249 Hemmungsloser Hinterhoftoilettensex - https://freakshow.fm/fs249-hemmungsloser-hinterhoftoilettensex - Mon, 27 Apr 2020 10:05:37 +0000 - podlove-2020-04-27t09:29:08+00:00-0afb684ad7267f3 - - - - 04:05:36 - Metaebene Personal Media - Tim Pritlove - Die Corona-Situation — Masken und Zauberwürfel — Gesundheitstechnologie — Differential Privacy — macOS auf ARM — Programmiersprachen - 249 - full - Heute begrüßen wir in unserer Runde den Menschen, der jetzt schon seit Jahren auf die eine oder andere Art und Weise zu hören war, nur noch nicht selbst: Rainer, der seinerzeit die Produktion der Previouslys von David übernommen hatte nimmt Platz in unserer Runde. Inhaltlich dreht sich natürlich viel um Das Unvermeidliche Thema ™, aber wir versuchen noch das eine oder andere sinnvolle zur Debatte hinzuzufügen. Und wir mussten mal wieder über Macs reden. Viel Spaß dabei. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Die Corona-Situation — Masken und Zauberwürfel — Gesundheitstechnologie — Differential Privacy — macOS auf ARM — Programmiersprachen

- -

Heute begrüßen wir in unserer Runde den Menschen, der jetzt schon seit Jahren auf die eine oder andere Art und Weise zu hören war, nur noch nicht selbst: Rainer, der seinerzeit die Produktion der Previouslys von David übernommen hatte nimmt Platz in unserer Runde. Inhaltlich dreht sich natürlich viel um Das Unvermeidliche Thema ™, aber wir versuchen noch das eine oder andere sinnvolle zur Debatte hinzuzufügen. Und wir mussten mal wieder über Macs reden. Viel Spaß dabei.

- -

Dauer: 4:05:36

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Letty - - - -Lettys Wunschliste Icon - - -
- -avatar - - -Denis Ahrens - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Clemens Schrimpe - -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
-Support -
- -avatar - - -Rainer -
Previously -
- - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Letty - - - Denis Ahrens - - - Clemens Schrimpe - - - Rainer - -
- - FS248 Public Static Final - https://freakshow.fm/fs248-public-static-final - Tue, 31 Mar 2020 07:57:09 +0000 - podlove-2020-03-30t23:22:33+00:00-0d806fba61c9b50 - - - - 03:23:01 - Metaebene Personal Media - Tim Pritlove - Die erste Freak Show, die komplett remote stattfindet - 248 - full - Nun ist es es also soweit: der Coronavirus zwingt auch die Freak Show in den Zwangsabstand und so wird das erste mal nicht live und lebendig in der Metaebene aufgenommen, sondern wir finden uns alle digital zusammen. Klappt trotzdem irgendwie und wir bieten seit langem mal wieder ein volles Team. Die Themen liegen natürlich auf der Hand, aber wir reden auch mal wieder über Macs. Viel Spaß. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Die erste Freak Show, die komplett remote stattfindet

- -

Nun ist es es also soweit: der Coronavirus zwingt auch die Freak Show in den Zwangsabstand und so wird das erste mal nicht live und lebendig in der Metaebene aufgenommen, sondern wir finden uns alle digital zusammen. Klappt trotzdem irgendwie und wir bieten seit langem mal wieder ein volles Team. Die Themen liegen natürlich auf der Hand, aber wir reden auch mal wieder über Macs. Viel Spaß.

- -

Dauer: 3:23:01

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Letty - - - -Lettys Wunschliste Icon - - -
- -avatar - - -hukl - - - -Thomann Wishlist Icon - - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Tala - - - -Amazon Wishlist Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Clemens Schrimpe - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Letty - - - hukl - - - Tala - - - roddi - - - Clemens Schrimpe - -
- - FS247 Pulp-Fiction-Koffermoment - https://freakshow.fm/fs247-pulp-fiction-koffermoment - Thu, 27 Feb 2020 21:32:03 +0000 - podlove-2020-02-27t19:11:42+00:00-44e5ad9cc461a0e - - - - 04:02:47 - Metaebene Personal Media - Tim Pritlove - Umziehen — Podlove Web Player — Podlove Publisher — WordPress — Podlove Radiator — Küchengeräte - 247 - full - Heute finden wir uns mit einer ganzen Reihe an Wiedergängern aus den letzten Jahren zusammen. Wir begrüßen Dennis Morhardt, Alexander Heimbuch und Eric Teubert in unserer Runde und reden viel über Podlove und Podcasting, aber auch darüber, wie man sich richtig die Hände wäscht und ohne welchen Küchengeräte ein Leben im 21. Jahrhundert unvorstellbar ist. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Umziehen — Podlove Web Player — Podlove Publisher — WordPress — Podlove Radiator — Küchengeräte

- -

Heute finden wir uns mit einer ganzen Reihe an Wiedergängern aus den letzten Jahren zusammen. Wir begrüßen Dennis Morhardt, Alexander Heimbuch und Eric Teubert in unserer Runde und reden viel über Podlove und Podcasting, aber auch darüber, wie man sich richtig die Hände wäscht und ohne welchen Küchengeräte ein Leben im 21. Jahrhundert unvorstellbar ist.

- -

Dauer: 4:02:47

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -roddi - - - -Amazon Wishlist Icon - - - - -Bitcoin Icon - - -
- -avatar - - -Eric Teubert - -
- -avatar - - -Dennis Morhardt - -
- -avatar - - -Alexander Heimbuch - - - -Amazon Wishlist Icon - - -
-Support -
- -avatar - - -Rainer -
Previously on Freak Show -
- - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - roddi - - - Eric Teubert - - - Dennis Morhardt - - - Alexander Heimbuch - -
- - FS246 Raumzeitfenster - https://freakshow.fm/fs246-raumzeitfenster - Thu, 30 Jan 2020 13:10:47 +0000 - podlove-2020-01-30t10:52:26+00:00-666de9cd437c1b9 - - - - 04:02:58 - Metaebene Personal Media - Tim Pritlove - Monty Python und Humor — Coronavirus — Living the Future — Raumzeit — Space — Tesla und die Automobilindustrie — Sozialraum Auto — Promotion — Billie Eilish - 246 - full - Eine kleine Runde mit Gast. Tala ist und Gregor ist mal wieder dazugestossen. Wenig überraschend gehen wir diverse Dinge stark auf der Metaebene an (im doppelten Wortsinne). Wir diskutieren Humor, Viren, Texteditoren, das Leben in der Zukunft und warum das mit der Abkehr vom Auto noch eine Weile dauern wird. - Feedback zur Sendung?
-Schreibe uns einen Kommentar

- -

Diese Sendung soll nie aufhören?
-Unterstütze die Metaebene mit einer Spende -

- - -

Monty Python und Humor — Coronavirus — Living the Future — Raumzeit — Space — Tesla und die Automobilindustrie — Sozialraum Auto — Promotion — Billie Eilish

- -

Eine kleine Runde mit Gast. Tala ist und Gregor ist mal wieder dazugestossen. Wenig überraschend gehen wir diverse Dinge stark auf der Metaebene an (im doppelten Wortsinne). Wir diskutieren Humor, Viren, Texteditoren, das Leben in der Zukunft und warum das mit der Abkehr vom Auto noch eine Weile dauern wird.

- -

Dauer: 4:02:58

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-On Air -
- -avatar - - -Tim Pritlove - - - -Bitcoin Icon - - - - -Amazon Wishlist Icon - - - - -Liberapay Icon - - - - -SEPA-Überweisung via Online-Banking-Software Icon - - - - -Paypal Icon - - -
- -avatar - - -Tala - - - -Amazon Wishlist Icon - - -
- -avatar - - -Gregor Sedlag - -
-Support -
- -avatar - - -Rainer - - - -Bitcoin Icon - - -
- -avatar - - -Studio Link On Air - -
- - - - - -Shownotes: - - - - - - - -
-]]>
- - - - - - - - - - - - - - - - - - - - - 2 - - Tim Pritlove - http://tim.pritlove.org/ - - - Tala - - - Gregor Sedlag - -
- + FS245 Lazy Letty https://freakshow.fm/fs245-lazy-letty Fri, 10 Jan 2020 19:33:54 +0000 -- GitLab From 885688a8b21d6828e2c0bc93ddd5a64a3818cc02 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Sat, 30 Jan 2021 16:39:20 +0100 Subject: [PATCH 2/6] fixed linter errors --- python/podcast/archive.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/podcast/archive.py b/python/podcast/archive.py index ba5fa93..a7346e7 100644 --- a/python/podcast/archive.py +++ b/python/podcast/archive.py @@ -1,10 +1,8 @@ """ Archive of listened poposts """ -import datetime import sys import time -from typing import List, Any sys.path.append("../") -- GitLab From 2d0567c372f81becee5f68967fc9a9d51bf03fd9 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Sat, 30 Jan 2021 16:42:14 +0100 Subject: [PATCH 3/6] fixed 3.8 interoperatibility --- python/podcast/archive.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/podcast/archive.py b/python/podcast/archive.py index a7346e7..f160ecd 100644 --- a/python/podcast/archive.py +++ b/python/podcast/archive.py @@ -3,6 +3,7 @@ Archive of listened poposts """ import sys import time +from typing import List sys.path.append("../") @@ -28,7 +29,7 @@ class Archive: """ The podcast Archive. It has a list of podposts """ - _archive_entries: list[ArchiveEntry] + _archive_entries: List[ArchiveEntry] def __init__(self): """ -- GitLab From cae5472dec77c69e736943d141e66e274e328708 Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Mon, 1 Feb 2021 21:10:23 +0100 Subject: [PATCH 4/6] fixed tests, small refactorings, sorting by Podpost::insert_date again --- pytest.ini | 5 +++++ python/podcast/archive.py | 12 ++++++++++-- python/podcast/data_migration.py | 22 ++++++++++++---------- python/podcast/podpost.py | 22 ++++++++-------------- qml/components/ArchiveHandler.py | 20 +++++--------------- test/__init__.py | 5 +++++ test/test_archive.py | 11 +++++++---- test/test_migration_to_v1.py | 3 +++ test/test_queue.py | 11 +++++++---- 9 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..a861829 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +log_cli = 1 +log_cli_level = Info +testpaths = + test \ No newline at end of file diff --git a/python/podcast/archive.py b/python/podcast/archive.py index f160ecd..1f7f7dc 100644 --- a/python/podcast/archive.py +++ b/python/podcast/archive.py @@ -3,18 +3,19 @@ Archive of listened poposts """ import sys import time -from typing import List +from typing import List, Iterator sys.path.append("../") from podcast.singleton import Singleton from podcast.factory import Factory +from podcast.podpost import Podpost archivename = "the_archive" class ArchiveEntry: - insert_date: float + insert_date: float # unused yet podpost: str @classmethod @@ -66,6 +67,13 @@ class Archive: for archive_entry in sorted(self._archive_entries, key=lambda e: e.insert_date, reverse=True): yield archive_entry.podpost + def get_podpost_objects(self, url_filter=None) -> Iterator[Podpost]: + for id in self.get_podposts(): + entry: Podpost = Factory().get_podpost(id) + if entry: + if not url_filter or (url_filter and entry.podurl == url_filter): + yield entry + def remove_podpost(self, podpost): """ Remove a podpost from archive diff --git a/python/podcast/data_migration.py b/python/podcast/data_migration.py index 7fd6ccc..5cbe69d 100644 --- a/python/podcast/data_migration.py +++ b/python/podcast/data_migration.py @@ -1,3 +1,4 @@ +import datetime import logging import os from typing import List @@ -75,7 +76,7 @@ def migrate_archive_v0_v1(): archive: Archive = ArchiveFactory().get_archive() if hasattr(archive, "podposts") and len(archive.podposts) > 0 and type(archive.podposts) is not ArchiveEntry: old_archive: List[str] = archive.podposts - archive.__archive_entries = [] + archive._archive_entries = [] for postid in old_archive: archive_entry = ArchiveEntry() post = Factory().get_podpost(postid) @@ -86,19 +87,20 @@ def migrate_archive_v0_v1(): else: archive_entry.insert_date = datetime.datetime.now() archive_entry.podpost = postid - archive.__archive_entries.append(post) + archive._archive_entries.append(post) del archive.podposts def migrate_podpost_v0_v1(self: Podpost): - if hasattr(self, "entry"): - if not hasattr(self, "isaudio"): - self.isaudio = False - if not hasattr(self, "length"): - self.length = 0 - if not self.isaudio: - self.init(self.entry, self.logo_url, self.podurl) - self.save() + if not hasattr(self, "insert_date") or self.insert_date is None: + self.insert_date = datetime.datetime.now().timestamp() + if not hasattr(self, "isaudio"): + self.isaudio = False + if not hasattr(self, "length"): + self.length = 0 + if hasattr(self, "entry") and not self.isaudio: + self.init(self.entry, self.logo_url, self.podurl) + self.save() def migrate_podcast_v0_v1(self: Podcast): diff --git a/python/podcast/podpost.py b/python/podcast/podpost.py index d59b89d..e263fad 100644 --- a/python/podcast/podpost.py +++ b/python/podcast/podpost.py @@ -1,7 +1,7 @@ """ Podpost: a single podcast post """ - +import datetime import sys sys.path.append("../") @@ -41,7 +41,7 @@ class Podpost: title: str percentage: float position: int - isaudio: bool + isaudio: bool # if the post comes from the external folder id: str state: int favorite: bool @@ -51,13 +51,12 @@ class Podpost: href: str duration: Optional[int] length: int - published: Optional[float] - insert_date: object + published: Optional[float] # when the post was published according to feed + insert_date: float # when we entered this post into our db link: Optional[str] type: str - podurl: str + podurl: str # the feed url chapters: List - version: int def __init__(self, entry, podurl, logo_url, data=None, isaudio=False): """ @@ -75,6 +74,7 @@ class Podpost: self.length = 0 self.type = "" self.href = "" + self.insert_date = datetime.datetime.now().timestamp() if isaudio: self.init_file_entry(data, logo_url, podurl) @@ -93,7 +93,6 @@ class Podpost: self.id = data["id"] self.length = int(data["length"]) self.published = 0 - self.insert_date = None self.link = None self.type = data["mime"] self.podurl = podurl @@ -107,7 +106,6 @@ class Podpost: if len(logo_url) > 0: if logo_url[0] == "/": self.logo_path = logo_url - self.insert_date = None try: self.published = timegm(entry.published_parsed) except: @@ -262,12 +260,8 @@ class Podpost: section = format_full_date(self.published) date = self.published fdate = s_to_year(date) - if self.insert_date: - asection = format_full_date(self.insert_date) - adate = self.insert_date - else: - asection = "" - adate = 0 + asection = format_full_date(self.insert_date) + adate = self.insert_date logger.debug("adate, asection %s, %s", adate, asection) logger.debug("date, section %s, %s", date, section) if self.duration: diff --git a/qml/components/ArchiveHandler.py b/qml/components/ArchiveHandler.py index 4a48d88..bc3edf3 100644 --- a/qml/components/ArchiveHandler.py +++ b/qml/components/ArchiveHandler.py @@ -9,28 +9,18 @@ sys.path.append("/usr/share/harbour-podqast/python") from podcast.archive import ArchiveFactory from podcast.factory import Factory +import logging +logger = logging.getLogger(__name__) def get_archive_posts(podurl=None): """ Return a list of all archive posts """ - entries = [] - archive = ArchiveFactory().get_archive() - - for archive_entry in archive.get_podposts(sorted_by_date=True): - entry = Factory().get_podpost(archive_entry.podpost) - if podurl: - if entry.podurl == podurl: - entries.append(entry.get_data()) - else: - if entry: - entries.append(entry.get_data()) - else: - pyotherside.send("ArchiveHandler: We have a none object") - - pyotherside.send("createArchiveList", entries) + posts = ArchiveFactory().get_archive().get_podpost_objects(url_filter=podurl) + sorted_posts = sorted(posts, key=lambda p: p.insert_date, reverse=True) + pyotherside.send("createArchiveList", [post.get_data() for post in sorted_posts]) def get_archive_pod_data(): diff --git a/test/__init__.py b/test/__init__.py index 30af4ca..c174ad0 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,3 +1,5 @@ +import os +import tempfile import types import sys from unittest.mock import Mock @@ -9,3 +11,6 @@ def mock_pyotherside(): module.send = Mock(name=module_name+'.send') mock_pyotherside() + +os.environ["PODQAST_HOME"] = tempfile.gettempdir() +print("tempdir: %s"%os.environ["PODQAST_HOME"] ) diff --git a/test/test_archive.py b/test/test_archive.py index a951a22..a1b958e 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -5,7 +5,6 @@ test the archive import sys from httpretty import HTTPretty, httprettified - from test.test_podcast import read_testdata, xml_headers sys.path.append("../python") @@ -51,9 +50,13 @@ def test_insert(): entry2.save() archive.insert(entry2.id) - result_posts = list(archive.get_podposts(sorted_by_date=True)) - assert entry1.id == result_posts[1] # older - assert entry2.id == result_posts[0] # newer + result_posts = list(archive.get_podposts()) + assert entry1.id in result_posts + assert entry2.id in result_posts + object_ids = [a.id for a in archive.get_podpost_objects('https://freakshow.fm/feed/opus/')] + assert entry1.id in object_ids + assert entry2.id in object_ids + assert 0 == len(list(archive.get_podpost_objects(url_filter='https://i.am.not.corrects/speex'))) def test_get_archives(): """ diff --git a/test/test_migration_to_v1.py b/test/test_migration_to_v1.py index c694f0c..c8fc258 100644 --- a/test/test_migration_to_v1.py +++ b/test/test_migration_to_v1.py @@ -27,6 +27,9 @@ def test_migration(): podcast: Podcast = PodcastFactory().get_podcast(podcasts[0]) assert podcast != None assert len(podcast.entry_ids_old_to_new) == 22 + for post in (Factory().get_podpost(post) for post in podcast.entry_ids_old_to_new for podcast in + map(PodcastFactory().get_podcast, podcasts)): + assert post.insert_date is not None assert len(list(podcast.get_entries())) == 22 del os.environ["PODQAST_HOME"] resetSingletons() diff --git a/test/test_queue.py b/test/test_queue.py index 0927ba5..f2e166d 100644 --- a/test/test_queue.py +++ b/test/test_queue.py @@ -14,9 +14,8 @@ sys.path.append("../python") from podcast.queue import QueueFactory from podcast.factory import Factory from podcast.queue import Queue -from podcast.podcast import Podcast +from podcast.podcast import Podcast, PodcastFactory from podcast.podpost import Podpost -import podcast def test_create_queue(): @@ -70,10 +69,14 @@ def test_get_podposts(): """ queue = QueueFactory().get_queue() - queue.podposts = ['85140fc8e16ba62517877ef4857a85f5bbf83e6a236c659a73489f093e51f154', - 'ce656a3888a282fe9df727e0729fa7d375704e4bd6c0d50e9c0fe7ddafa232ec'] + podcast = PodcastFactory().get_podcast('https://freakshow.fm/feed/opus/') + entry = podcast.entry_ids_old_to_new[1] + entry2 = podcast.entry_ids_old_to_new[0] + queue.insert_top(entry) + queue.insert_top(entry2) postids = list(queue.get_podposts()) assert len(postids) == 2 for post in postids: assert type(post) == str assert type(Factory().get_podpost(post)) == Podpost + assert post in [entry,entry2] -- GitLab From 6d79cdef668bd638cc913fd9608a52e660ff7c7a Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Mon, 1 Feb 2021 21:20:06 +0100 Subject: [PATCH 5/6] removed adate completly, sorting everything by insert_date now --- python/podcast/podpost.py | 4 ---- qml/components/FavoriteHandler.py | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/python/podcast/podpost.py b/python/podcast/podpost.py index e263fad..39beaa2 100644 --- a/python/podcast/podpost.py +++ b/python/podcast/podpost.py @@ -261,9 +261,6 @@ class Podpost: date = self.published fdate = s_to_year(date) asection = format_full_date(self.insert_date) - adate = self.insert_date - logger.debug("adate, asection %s, %s", adate, asection) - logger.debug("date, section %s, %s", date, section) if self.duration: duration = s_to_hr(self.duration) else: @@ -294,7 +291,6 @@ class Podpost: "date": date, "fdate": fdate, "section": section, - "adate": adate, "asection": asection, "length": self.length, "duration": duration, diff --git a/qml/components/FavoriteHandler.py b/qml/components/FavoriteHandler.py index e19a9a9..9ea0aab 100644 --- a/qml/components/FavoriteHandler.py +++ b/qml/components/FavoriteHandler.py @@ -79,10 +79,8 @@ def get_favorites(podurl=None): posts = get_queue_favorites(podurl) posts = append_archive_favorites(posts, podurl=podurl) postsdata = [] - for post in posts: + for post in sorted(posts, key=lambda p: p.insert_date, reverse=True): postsdata.append(post.get_data()) - - postsdata.sort(key=lambda r: r["adate"], reverse=True) pyotherside.send("favoriteList", postsdata) -- GitLab From e9e9e3f4bac77004376ade6556a455b343b0368e Mon Sep 17 00:00:00 2001 From: Thilo Kogge Date: Mon, 1 Feb 2021 22:06:44 +0100 Subject: [PATCH 6/6] moved favorite logic to main package, added tests, fixed tests, stabilized tests --- python/podcast/archive.py | 7 ++- python/podcast/favorite.py | 80 ++++++++++++++++++++++++++++ qml/components/FavoriteHandler.py | 87 +++---------------------------- test/__init__.py | 14 ++++- test/test_archive.py | 36 ++++++++----- test/test_favorites.py | 35 +++++++++++++ test/test_queue.py | 28 +++++++++- 7 files changed, 188 insertions(+), 99 deletions(-) create mode 100644 python/podcast/favorite.py create mode 100644 test/test_favorites.py diff --git a/python/podcast/archive.py b/python/podcast/archive.py index 1f7f7dc..9318ec5 100644 --- a/python/podcast/archive.py +++ b/python/podcast/archive.py @@ -20,6 +20,8 @@ class ArchiveEntry: @classmethod def of_podpost(cls, postid: str): + if not type(postid) == str: + raise ValueError("did not get the id of a post") archive_entry = ArchiveEntry() archive_entry.podpost = postid archive_entry.insert_date = time.time() @@ -47,11 +49,12 @@ class Archive: store = Factory().get_store() store.store(archivename, self) - def insert(self, podpost): + def insert(self, podpost: str): """ Insert an podost """ - + if type(podpost) != str: + raise ValueError("please supply the id of the post") if podpost not in [e.podpost for e in self._archive_entries]: self._archive_entries.insert(0, ArchiveEntry.of_podpost(podpost)) self.save() diff --git a/python/podcast/favorite.py b/python/podcast/favorite.py new file mode 100644 index 0000000..6117218 --- /dev/null +++ b/python/podcast/favorite.py @@ -0,0 +1,80 @@ +from podcast.factory import Factory + + +def get_queue_favorites(podurl=None): + """ + Return a list of all favorites posts from queue + """ + + from podcast.queue import QueueFactory + + posts = [] + + queue = QueueFactory().get_queue() + for post in queue.get_podposts(): + p = Factory().get_podpost(post) + try: + if p.favorite: + if podurl: + if p.podurl == podurl: + posts.append(p) + else: + posts.append(p) + except: + pass + return posts + + +def append_archive_favorites(posts, podurl=None): + """ + append archive favorites to posts list + """ + + from podcast.archive import ArchiveFactory + + archive = ArchiveFactory().get_archive() + + for post in archive.get_podposts(): + p = Factory().get_podpost(post) + try: + if p.favorite: + if p not in posts: + if podurl: + if p.podurl == podurl: + posts.append(p) + else: + posts.append(p) + except: + pass + + return posts + + +def get_favorites(podurl=None): + """ + Test + """ + + posts = get_queue_favorites(podurl) + posts = append_archive_favorites(posts, podurl=podurl) + yield from sorted(posts, key=lambda p: p.insert_date, reverse=True) + + +def get_favorite_podcast_stats(): + """ + """ + + entries = {} + + posts = get_queue_favorites() + posts = append_archive_favorites(posts) + for p in posts: + if p.podurl in entries: + entries[p.podurl]["count"] += 1 + else: + if p.logo_url: + logo_url = p.logo_url + else: + logo_url = "../../images/podcast.png" + entries[p.podurl] = {"count": 1, "logo_url": logo_url} + return entries diff --git a/qml/components/FavoriteHandler.py b/qml/components/FavoriteHandler.py index 9ea0aab..98dfd6b 100644 --- a/qml/components/FavoriteHandler.py +++ b/qml/components/FavoriteHandler.py @@ -6,6 +6,7 @@ import threading import sys sys.path.append("/usr/share/harbour-podqast/python") +import podcast.favorite as favorite from podcast.factory import Factory @@ -22,87 +23,11 @@ def toggle_favorite(podpost, do_download=False): pyotherside.send("favoriteToggled", podpost, post.toggle_fav(do_download)) -def get_queue_favorites(podurl=None): - """ - Return a list of all favorites posts from queue - """ - - from podcast.queue import QueueFactory - - posts = [] - - queue = QueueFactory().get_queue() - for post in queue.get_podposts(): - p = Factory().get_podpost(post) - try: - if p.favorite: - if podurl: - if p.podurl == podurl: - posts.append(p) - else: - posts.append(p) - except: - pass - return posts - - -def append_archive_favorites(posts, podurl=None): - """ - append archive favorites to posts list - """ - - from podcast.archive import ArchiveFactory - - archive = ArchiveFactory().get_archive() - - for post in archive.get_podposts(): - p = Factory().get_podpost(post) - try: - if p.favorite: - if p not in posts: - if podurl: - if p.podurl == podurl: - posts.append(p) - else: - posts.append(p) - except: - pass - - return posts - - -def get_favorites(podurl=None): - """ - Test - """ - - posts = get_queue_favorites(podurl) - posts = append_archive_favorites(posts, podurl=podurl) - postsdata = [] - for post in sorted(posts, key=lambda p: p.insert_date, reverse=True): - postsdata.append(post.get_data()) - pyotherside.send("favoriteList", postsdata) - +def send_favorites(podurl=None): + pyotherside.send("favoriteList", [p.get_data() for p in favorite.get_favorites(podurl)]) def get_fav_pod_data(): - """ - """ - - entries = {} - - posts = get_queue_favorites() - posts = append_archive_favorites(posts) - for p in posts: - if p.podurl in entries: - entries[p.podurl]["count"] += 1 - else: - if p.logo_url: - logo_url = p.logo_url - else: - logo_url = "../../images/podcast.png" - entries[p.podurl] = {"count": 1, "logo_url": logo_url} - - pyotherside.send("archivePodList", entries) + pyotherside.send("archivePodList", favorite.get_favorite_podcast_stats()) class FavoriteHandler: @@ -125,10 +50,10 @@ class FavoriteHandler: return if podurl: self.bgthread2 = threading.Thread( - target=get_favorites, args=[podurl] + target=send_favorites, args=[podurl] ) else: - self.bgthread2 = threading.Thread(target=get_favorites) + self.bgthread2 = threading.Thread(target=send_favorites) self.bgthread2.start() def getfavpoddata(self): diff --git a/test/__init__.py b/test/__init__.py index c174ad0..2de8407 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -4,13 +4,23 @@ import types import sys from unittest.mock import Mock + def mock_pyotherside(): module_name = "pyotherside" module = types.ModuleType(module_name) sys.modules[module_name] = module - module.send = Mock(name=module_name+'.send') + module.send = Mock(name=module_name + '.send') + mock_pyotherside() os.environ["PODQAST_HOME"] = tempfile.gettempdir() -print("tempdir: %s"%os.environ["PODQAST_HOME"] ) +print("tempdir: %s" % os.environ["PODQAST_HOME"]) + + +def cleanup_archive(): + from podcast.archive import ArchiveFactory + archive = ArchiveFactory().get_archive() + for post in archive.get_podposts(): + archive.remove_podpost(post) + archive.save() diff --git a/test/test_archive.py b/test/test_archive.py index a1b958e..2c8e7a8 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -5,6 +5,8 @@ test the archive import sys from httpretty import HTTPretty, httprettified + +from . import cleanup_archive from test.test_podcast import read_testdata, xml_headers sys.path.append("../python") @@ -14,6 +16,7 @@ from podcast.factory import Factory from podcast.podcast import Podcast from podcast.podpost import Podpost + def test_create_archive(): """ test if archive is created @@ -25,6 +28,7 @@ def test_create_archive(): a2 = ArchiveFactory().get_archive() assert a1 == a2 + def test_archive_save(): """ does the archive save itself? @@ -33,41 +37,47 @@ def test_archive_save(): a = ArchiveFactory().get_archive() a.save() -@httprettified + def test_insert(): """ """ + + archive = ArchiveFactory().get_archive() + entry1, entry2 = setup_archive_with_2_posts(archive) + + result_posts = list(archive.get_podposts()) + assert entry1.id in result_posts + assert entry2.id in result_posts + object_ids = [a.id for a in archive.get_podpost_objects('https://freakshow.fm/feed/opus/')] + assert entry1.id in object_ids + assert entry2.id in object_ids + assert 0 == len(list(archive.get_podpost_objects(url_filter='https://i.am.not.corrects/speex'))) + + +@httprettified +def setup_archive_with_2_posts(archive): HTTPretty.register_uri(HTTPretty.GET, 'https://freakshow.fm/feed/opus/', body=read_testdata('testdata/freakshow.rss'), adding_headers=xml_headers) - - archive = ArchiveFactory().get_archive() podcast = Podcast('https://freakshow.fm/feed/opus/') entry1 = podcast.get_entry(podcast.entry_ids_old_to_new[0]) entry1.save() archive.insert(entry1.id) - entry2 = podcast.get_entry(podcast.entry_ids_old_to_new[1]) entry2.save() archive.insert(entry2.id) + return entry1, entry2 - result_posts = list(archive.get_podposts()) - assert entry1.id in result_posts - assert entry2.id in result_posts - object_ids = [a.id for a in archive.get_podpost_objects('https://freakshow.fm/feed/opus/')] - assert entry1.id in object_ids - assert entry2.id in object_ids - assert 0 == len(list(archive.get_podpost_objects(url_filter='https://i.am.not.corrects/speex'))) def test_get_archives(): """ Test listing of podposts """ - + cleanup_archive() a = ArchiveFactory().get_archive() + setup_archive_with_2_posts(a) count = 0 for post in a.get_podposts(): assert type(post) == str assert type(Factory().get_podpost(post)) == Podpost count += 1 - # make sure to clean ~/.local/share/harbour-podqast if this fails assert count == 2 diff --git a/test/test_favorites.py b/test/test_favorites.py new file mode 100644 index 0000000..c41e8fc --- /dev/null +++ b/test/test_favorites.py @@ -0,0 +1,35 @@ +from httpretty import HTTPretty, httprettified + +from podcast.archive import ArchiveFactory +from podcast.factory import Factory +from . import cleanup_archive +from test.test_podcast import read_testdata, xml_headers + + +@httprettified +def test_queue_favorites(): + """ + Test listing of podposts + """ + HTTPretty.register_uri(HTTPretty.GET, 'https://freakshow.fm/feed/opus/', + body=read_testdata('testdata/freakshow.rss'), adding_headers=xml_headers) + + from podcast import favorite + from podcast.podcast import PodcastFactory + cleanup_archive() + + url = 'https://freakshow.fm/feed/opus/' + podcast = PodcastFactory().get_podcast(url) + fav_posts = [Factory().get_podpost(podcast.entry_ids_old_to_new[i]) for i in range(0, 10, 2)] + assert len(fav_posts) == 5 + archive = ArchiveFactory().get_archive() + assert len(list(archive.get_podposts())) == 0 + for post in fav_posts: + post.favorite = True + post.save() + archive.insert(post.id) + archive.save() + assert len(favorite.get_queue_favorites()) == 0 + assert len(list(favorite.get_favorites())) == 5 + assert len(favorite.get_favorite_podcast_stats()) == 1 + assert favorite.get_favorite_podcast_stats()[url]['count'] == 5 diff --git a/test/test_queue.py b/test/test_queue.py index f2e166d..7043775 100644 --- a/test/test_queue.py +++ b/test/test_queue.py @@ -38,6 +38,7 @@ def test_queue_save(): q = QueueFactory().get_queue() q.save() + @httpretty.activate def test_insert_top(): """ @@ -79,4 +80,29 @@ def test_get_podposts(): for post in postids: assert type(post) == str assert type(Factory().get_podpost(post)) == Podpost - assert post in [entry,entry2] + assert post in [entry, entry2] + + +def test_queue_favorites(): + """ + Test listing of podposts + """ + from podcast import favorite + + queue = QueueFactory().get_queue() + url = 'https://freakshow.fm/feed/opus/' + podcast = PodcastFactory().get_podcast(url) + for post in (Factory().get_podpost(podcast.entry_ids_old_to_new[i]) for i in range(0, 10, 2)): + post.favorite = True + post.save() + for id in podcast.entry_ids_old_to_new: + queue.insert_bottom(id) + assert len(queue.podposts) == 20 + assert len(favorite.get_queue_favorites('https://wrong.url')) == 0 + assert [fav.id for fav in favorite.get_queue_favorites()] == [podcast.entry_ids_old_to_new[i] for i in + range(0, 10, 2)] + assert len(favorite.get_queue_favorites(url)) == 5 + for id in podcast.entry_ids_old_to_new: + queue.remove(id) + assert len(queue.podposts) == 0 + assert len(favorite.get_queue_favorites()) == 0 -- GitLab