Let's go Python 3 only, so I can get coloured logging
authorAlex Chan <alex@alexwlchan.net>
Sat, 4 Jan 2020 18:52:40 +0000 (18:52 +0000)
committerAlex Chan <alex@alexwlchan.net>
Sat, 4 Jan 2020 18:52:40 +0000 (18:52 +0000)
README.md
download_overcast_podcasts.py
requirements.in [new file with mode: 0644]
requirements.txt [new file with mode: 0644]

index 2760c55..07fceb7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -39,9 +39,13 @@ You need:
     You can create this in the Overcast iOS app.
     If you haven't done this before, or you've forgotten your email/password, read [my instructions](add_email_password) for doing so.
 
-*   **Somewhere where you can run Python scripts.**
-    The script should run with any recent version of Python (both 2.7 and 3.x), without any third-party packages.
-    For example, the system Python in macOS, or Pythonista on iOS.
+*   **A working Python 3 installation.**
+    This script only works with Python 3.
+    You need to install dependencies with pip:
+
+    ```console
+    $ pip3 install -r requirements.txt
+    ```
 
 Steps:
 
index 43e5158..48caf06 100755 (executable)
@@ -12,18 +12,20 @@ for every episode you've listened to.
 
 import argparse
 import errno
+import logging
 import json
 import os
 import sys
+from urllib.parse import urlparse
+from urllib.request import build_opener, install_opener, urlretrieve
 import xml.etree.ElementTree as ET
 
-try:
-    from urllib.parse import urlparse
-    from urllib.request import build_opener, install_opener, urlretrieve
-except ImportError:  # Python 2.7
-    from urllib import urlretrieve
-    from urllib2 import build_opener, install_opener
-    from urlparse import urlparse
+import daiquiri
+
+
+daiquiri.setup(level=logging.INFO)
+
+logger = daiquiri.getLogger(__name__)
 
 
 def parse_args(argv):
@@ -177,15 +179,17 @@ def download_episode(episode, download_dir):
 
     # Download the MP3 file for the episode, if it hasn't been downloaded already.
     if os.path.exists(download_path):
-        print("*** Already downloaded %s, skipping" % audio_url)
+        logger.debug("Already downloaded %s, skipping", audio_url)
     else:
-        print("*** Downloading %s" % audio_url)
+        logger.info(
+            "Downloading %s: %s to %s", episode["podcast"]["title"], audio_url, filename
+        )
         try:
             tmp_path, _ = urlretrieve(audio_url)
         except Exception as err:
-            print("*** Error downloading audio file: %s" % err)
+            logger.error("Error downloading audio file: %s", err)
         else:
-            print("*** Download successful!")
+            logger.info("Download successful!")
             os.rename(tmp_path, download_path)
 
     # Save a blob of JSON with some episode metadata
diff --git a/requirements.in b/requirements.in
new file mode 100644 (file)
index 0000000..68b1fb4
--- /dev/null
@@ -0,0 +1 @@
+daiquiri
diff --git a/requirements.txt b/requirements.txt
new file mode 100644 (file)
index 0000000..6c6f34b
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# This file is autogenerated by pip-compile
+# To update, run:
+#
+#    pip-compile
+#
+daiquiri==1.6.1