about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xPodWeb.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/PodWeb.py b/PodWeb.py
index 83c4f07..f33c878 100755
--- a/PodWeb.py
+++ b/PodWeb.py
@@ -5,10 +5,12 @@ import mimetypes
 import os
 import pprint
 import sqlite3
+import time
 import urllib
 import urllib.parse
 import urllib.request
 import xml.etree.ElementTree as xmlet
+from contextlib import nullcontext as ncxt
 
 import click
 import fake_useragent
@@ -152,7 +154,7 @@ class PodWeb:
                     "season"        INTEGER,
                     "deleted"       BOOL NOT NULL CHECK("deleted" in (0,1)),
                     "number"        INTEGER NOT NULL,
-                    "pubdate"       INTEGER,
+                    "pubdate"       INTEGER NOT NULL,
                     PRIMARY KEY("guid","podcast_url")
                 )
             """
@@ -342,7 +344,7 @@ class PodWeb:
             parsed["episodes"].reverse()
         with click.progressbar(
             length=len(parsed["episodes"]), label=f"Fetching {parsed['title']} episodes"
-        ) if progressbar else nullcontext() as bar:
+        ) if progressbar else ncxt() as bar:
             number = 1
             new_episodes_guids = []
             for i in parsed["episodes"]:
@@ -354,7 +356,7 @@ class PodWeb:
                     """,
                     {"GUID": i["guid"]},
                 )
-                isfound = self.execute.fetchone()[0]
+                isfound = self.data.fetchone()[0]
                 if isfound == 0:
                     new_episodes_guids.append(i["guid"])
                 enclosure_list = sorted(
@@ -423,6 +425,7 @@ class PodWeb:
                     """,
                     {"GUID": i},
                 )
+
         return new_episodes_guids
 
     def download_episode_index(
@@ -658,16 +661,33 @@ def fetch(obj: any, index: int | None, quiet: bool) -> None:
         click.echo(f"Podcast {index} does not exist.", err=True)
     elif index == None and serverlen != 1:
         with click.progressbar(obj.servers, label="Fetching episodes") as bar:
+            new_episodes_guids = []
             for i in bar:
                 if not quiet:
                     click.echo(i["name"])
-                new_episodes_guids = obj._sync_episodes(i["url"])
-        if not quiet:
-            obj.data.execute(
-                """
-                    SELECT "title"
-                """
+                new_episodes_guids += obj._sync_episodes(i["url"])
+        if not quiet and len(new_episodes_guids) > 0:
+            sql_query = """
+                SELECT "title","pubdate"
+                FROM "episodes"
+                WHERE guid IN ({sequence})
+                ORDER BY pubdate;
+            """.format(
+                sequence=",".join(["?"] * len(new_episodes_guids))
             )
+            sql_query = " ".join(sql_query.split())
+            response = obj.data.execute(sql_query, new_episodes_guids)
+            click.echo("NEW EPISODES:")
+            new_episode_list = response.fetchall()
+            for i in range(0, len(new_episode_list)):
+                if new_episode_list[i][1] != 0:
+                    ipubdate = time.strftime(
+                        "%m/%d/%y %H:%M %z", time.localtime(new_episode_list[i][1])
+                    )
+                    ipubdate = f"{ipubdate} - "
+                else:
+                    ipubdate = ""
+                click.echo(f"\t{i}: {ipubdate}{new_episode_list[i][0]}")
     else:
         obj._sync_episodes(obj.servers[index - 1]["url"], progressbar=True)