Implement configuration file, cleanup
authorJakob Cornell <jakob+gpg@jcornell.net>
Sat, 22 Feb 2020 05:39:30 +0000 (23:39 -0600)
committerJakob Cornell <jakob+gpg@jcornell.net>
Sat, 22 Feb 2020 05:39:30 +0000 (23:39 -0600)
hls_watch/__main__.py
setup.py

index fd24ad8108e84e39fde25065dde9d12063be08d9..f95f218887b10c65c51247d9aa5fbe153b559ee6 100644 (file)
@@ -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()
index ebf9e474daddb74401f911c721dc492da332026d..09ac2f9d3f8d863662b5843cf24b7e9993b77e07 100644 (file)
--- 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',
+       ],
 )