def main() -> None: arguments = docopt(__doc__) webcam_url = 'http://www.portoitapoa.com.br/images/camera/camera.jpeg' output_dir_path = Path(arguments['<output_dir>']) # Handle logging options if arguments['--verbose']: logger.setLevel(logging.DEBUG) if arguments['--quiet']: logging.disable(logging.CRITICAL) # Handle period option try: period = parse_period_arg(arguments['--period']) except ValueError as e: logger.critical("Error: %s", e) sys.exit(1) # Handle output dir argument, creates it if necessary try: os.makedirs(output_dir_path) except OSError as e: if e.errno != errno.EEXIST: logger.critical("Error: Unable to create output directory.") sys.exit(1) # Download in a loop! schedule.every(period).seconds.do( lambda: safe_download(webcam_url, output_dir_path)) while True: schedule.run_pending() time.sleep(1)
def cmd_update_online(args: Dict[str, str]) -> None: """ Updates a given database by downloading the current schedule spreadsheet from the website. Will run only once, or in a loop, depending on if a period is specified. """ # No period specified. Do it once. if args['--period'] is None: update_online_once(args['<database_path>']) return # Handle period option try: period = parse_period_arg(args['--period']) except ValueError as e: logger.critical("Error: %s", e) sys.exit(1) schedule.every(period).seconds.do( functools.partial(update_online_once, args['<database_path>'])) while True: schedule.run_pending() time.sleep(1)
def test_negative_period() -> None: with pytest.raises(ValueError): assert parse_period_arg('-1')
def test_valid_period() -> None: assert parse_period_arg('1') == 1
def test_non_numeric_period() -> None: with pytest.raises(ValueError): assert parse_period_arg('1e5')