diff --git a/README.md b/README.md index 43da16a..747d7f7 100644 --- a/README.md +++ b/README.md @@ -130,14 +130,15 @@ También tiene opción `--help` que muestra la ayuda particular de este sub-coma │ frts [FRTS]... List of frt codes separated by ' ' [default: None] │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ * --api-base-url TEXT [env var: ENERBIT_API_BASE_URL] [default: None] [required] │ -│ * --api-username TEXT [env var: ENERBIT_API_USERNAME] [default: None] [required] │ -│ * --api-password TEXT [env var: ENERBIT_API_PASSWORD] [default: None] [required] │ -│ --since [%Y-%m-%d|%Y%m%d] [default: (yesterday)] │ -│ --until [%Y-%m-%d|%Y%m%d] [default: (today)] │ -│ --timezone TEXT [default: America/Bogota] │ -│ --out-format [csv|jsonl] Output file format [default: jsonl] │ -│ --frt-file PATH Path file with one frt code per line [default: None] │ -│ --help Show this message and exit. │ +│ * --api-base-url TEXT [env var: ENERBIT_API_BASE_URL] [default: None] [required] │ +│ * --api-username TEXT [env var: ENERBIT_API_USERNAME] [default: None] [required] │ +│ * --api-password TEXT [env var: ENERBIT_API_PASSWORD] [default: None] [required] │ +│ --since [%Y-%m-%d|%Y%m%d] [default: (yesterday)] │ +│ --until [%Y-%m-%d|%Y%m%d] [default: (today)] │ +│ --timezone TEXT [default: America/Bogota] │ +│ --out-format [csv|jsonl] Output file format [default: jsonl] │ +│ --frt-file PATH Path file with one frt code per line [default: None] │ +│ --timeout INTEGER RANGE [0<=x<=20] [default: 5] │ +│ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/setup.py b/setup.py index 489ca4c..8f0a05a 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,7 @@ install_requires=[ "httpx", "typer", - "pydantic", + "pydantic>2", "tzdata", "urlpath", "rich", diff --git a/src/enerbitdso/VERSION b/src/enerbitdso/VERSION index 82551ad..345f8cc 100644 --- a/src/enerbitdso/VERSION +++ b/src/enerbitdso/VERSION @@ -1 +1 @@ -0.1.9 \ No newline at end of file +0.1.10 \ No newline at end of file diff --git a/src/enerbitdso/cli.py b/src/enerbitdso/cli.py index c8f45fd..5625517 100644 --- a/src/enerbitdso/cli.py +++ b/src/enerbitdso/cli.py @@ -60,8 +60,16 @@ def fetch( frt_file: pathlib.Path = typer.Option( None, help="Path file with one frt code per line" ), + timeout: int = typer.Option( + 5, + min=0, + max=20, + ), frts: list[str] = typer.Argument(None, help="List of frt codes separated by ' '"), ): + if timeout is not None: + enerbit.set_http_timeout(timeout) + try: ebclient = enerbit.get_client(api_base_url, api_username, api_password) except Exception: @@ -99,7 +107,7 @@ def fetch( ) except Exception: err_console.print(f"Failed to fetch usage records for frt code '{f}'") - # err_console.print_exception() + err_console.print_exception() continue match out_format: diff --git a/src/enerbitdso/enerbit.py b/src/enerbitdso/enerbit.py index 849495a..e0afd8d 100644 --- a/src/enerbitdso/enerbit.py +++ b/src/enerbitdso/enerbit.py @@ -37,6 +37,9 @@ class ScheduleMeasurementRecord(pydantic.BaseModel): reactive_energy_imported: float reactive_energy_exported: float +def set_http_timeout(timeout): + global TIMEOUT + TIMEOUT = httpx.Timeout(timeout, read=60) def get_auth_token(base_url, username, password): path = "/auth/token/" @@ -106,7 +109,7 @@ def get_schedule_measurement_records( response.raise_for_status() records = response.json() records = sorted(records, key=lambda r: r["time_local_utc"]) - measurement_records = [ScheduleMeasurementRecord.model_validate(r) for r in records] + measurement_records = records measurement_records = scale_measurement_records( measurement_records, scale=WATT_HOUR_TO_KILOWATT_HOUR )