diff --git a/pyproject.toml b/pyproject.toml index 31021d1..1e31638 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pywebcat" -version = "0.1.5" +version = "0.1.6" description = "Python tool for working with the NOAA NOS Web Camera Applications Testbed (WebCAT)" authors = ["Tomas Beuzen "] license = "MIT" diff --git a/pywebcat/__init__.py b/pywebcat/__init__.py index 1276d02..0a8da88 100644 --- a/pywebcat/__init__.py +++ b/pywebcat/__init__.py @@ -1 +1 @@ -__version__ = "0.1.5" +__version__ = "0.1.6" diff --git a/pywebcat/cli.py b/pywebcat/cli.py index afaebc7..4b31066 100644 --- a/pywebcat/cli.py +++ b/pywebcat/cli.py @@ -1,5 +1,4 @@ import os -import sys import argparse import itertools from pywebcat.utils import WebCAT @@ -22,19 +21,17 @@ def main(): wc = WebCAT() for item in itertools.product(station, year, month, day, time): try: - sys.stdout = open(os.devnull, "w") # capture any output from url generation wc.generate_url(*item) # generate url from the input data - sys.stdout = sys.__stdout__ # reinstate output tmp_dir = os.path.join(directory, item[0], wc.name) # dir to save frames in if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) # mkdir if not exist if verbose: print(f"Saving frames of {wc.name}...") wc.save_frames(interval, tmp_dir, not no_meta, verbose) # save frames - except: + except Exception as e: if verbose: url = f"http://webcat-video.axds.co/{item[0]}/raw/{item[1]}/{item[1]}_{item[2]:02}/{item[1]}_{item[2]:02}_{item[3]:02}/{item[0]}.{item[1]}-{item[2]:02}-{item[3]:02}_{item[4]:04}.mp4" - print(f"Warning: {url} not a valid url... Skipping.") + print(f"Error for url: {url}. Traceback: {e} Skipping this url.") def parse_args(): diff --git a/pywebcat/utils.py b/pywebcat/utils.py index bfc5e00..29a72e6 100644 --- a/pywebcat/utils.py +++ b/pywebcat/utils.py @@ -93,13 +93,14 @@ def generate_url(self, station: str, year: int, month: int, day: int, time: int) """ url = f"http://webcat-video.axds.co/{station}/raw/{year}/{year}_{month:02}/{year}_{month:02}_{day:02}/{station}.{year}-{month:02}-{day:02}_{time:04}.mp4" - vid = cv2.VideoCapture(url) - if int(vid.get(7)) == 0: # check if there are any frames + try: + urllib.request.urlopen(url) + except: raise ValueError(f"{url} is not a valid url.") - else: - self.url = url - self.video = vid - self.name = f"{station}_{year}_{month}_{day}_{time}" + vid = cv2.VideoCapture(url) + self.url = url + self.video = vid + self.name = f"{station}_{year}_{month}_{day}_{time}" def download_url(self, fout: str = None, verbose: bool = True): """Download the video from the instance url. @@ -144,9 +145,8 @@ def save_frames( raise ValueError( f"delta_t should be less than {int(self.frames / self.fps)}." ) - print(self.fps) step = delta_t * self.fps - step_range = range(0, (self.frames + 1), step) + step_range = range(0, (self.frames), step) loop = tqdm(step_range) if verbose else step_range tmp_dir = os.path.join(fout_path, "jpg") # save images in a "jpg" folder if os.path.exists(tmp_dir): diff --git a/tests/test_pywebcat.py b/tests/test_pywebcat.py index 26ec019..326c2a6 100644 --- a/tests/test_pywebcat.py +++ b/tests/test_pywebcat.py @@ -6,7 +6,7 @@ def test_version(): - assert __version__ == "0.1.5" + assert __version__ == "0.1.6" def test_generate_url():