Skip to content

Commit

Permalink
fix previous breaking changes, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasBeuzen committed Jul 7, 2020
1 parent 18c0be6 commit 50d4d2b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion pywebcat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.5"
__version__ = "0.1.6"
7 changes: 2 additions & 5 deletions pywebcat/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import argparse
import itertools
from pywebcat.utils import WebCAT
Expand All @@ -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():
Expand Down
16 changes: 8 additions & 8 deletions pywebcat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pywebcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_version():
assert __version__ == "0.1.5"
assert __version__ == "0.1.6"


def test_generate_url():
Expand Down

0 comments on commit 50d4d2b

Please sign in to comment.