From: Jakob Cornell Date: Sat, 22 Feb 2020 05:39:30 +0000 (-0600) Subject: Implement configuration file, cleanup X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=025cc8897dc66ebe6f859d0ea56427dc72e8dc11;p=hls-watch.git Implement configuration file, cleanup --- diff --git a/hls_watch/__main__.py b/hls_watch/__main__.py index fd24ad8..f95f218 100644 --- a/hls_watch/__main__.py +++ b/hls_watch/__main__.py @@ -10,7 +10,6 @@ def get_time(resp): time_str = resp.info().get('Date') time = None if time_str: - print(time_str) try: time = datetime.datetime.strptime(time_str, '%a, %d %b %Y %H:%M:%S %Z') except ValueError: @@ -23,23 +22,34 @@ def get_time(resp): if __name__ == '__main__': import argparse import contextlib + import os import pathlib import time import urllib.parse import urllib.request + import toml + ap = argparse.ArgumentParser() ap.add_argument("base_path") - ap.add_argument("url") + ap.add_argument("endpoint") args = ap.parse_args() base_path = pathlib.Path(args.base_path) assert base_path.is_dir() - url = args.url - url_path = pathlib.PurePosixPath(urllib.parse.urlparse(url).path) - endpoint = url_path.stem + cfg_path = ( + pathlib.Path( + os.getenv('XDG_CONFIG_HOME', os.getenv('HOME') + '/.config') + ) + .joinpath('oberlin_webcast2') + ) + with cfg_path.joinpath('config.toml').open() as f: + config = toml.load(f) + + endpoint = args.endpoint + url = config['endpoints'][endpoint] # Follow redirects but don't throw on 4XX opener = urllib.request.OpenerDirector() diff --git a/setup.py b/setup.py index ebf9e47..09ac2f9 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,9 @@ from setuptools import setup, find_packages setup( name = "hls_watch", - version = "0.0.0", + version = "0.1.0", packages = find_packages(), - install_requires = [], + install_requires = [ + 'toml<1', 'toml>=0.10', + ], )