novastar-client 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- novastar_client-1.2.0/PKG-INFO +76 -0
- novastar_client-1.2.0/README.md +62 -0
- novastar_client-1.2.0/pyproject.toml +33 -0
- novastar_client-1.2.0/pyproject.toml.orig +25 -0
- novastar_client-1.2.0/src/novastar_client/README.md +333 -0
- novastar_client-1.2.0/src/novastar_client/__init__.py +30 -0
- novastar_client-1.2.0/src/novastar_client/cli/__init__.py +11 -0
- novastar_client-1.2.0/src/novastar_client/cli/commands/__init__.py +11 -0
- novastar_client-1.2.0/src/novastar_client/cli/commands/stations.py +59 -0
- novastar_client-1.2.0/src/novastar_client/cli/commands/ts.py +111 -0
- novastar_client-1.2.0/src/novastar_client/cli/commands/tscatalog.py +77 -0
- novastar_client-1.2.0/src/novastar_client/cli/context.py +18 -0
- novastar_client-1.2.0/src/novastar_client/cli/helpers.py +26 -0
- novastar_client-1.2.0/src/novastar_client/cli/logging.py +80 -0
- novastar_client-1.2.0/src/novastar_client/cli/ns5acp.py +72 -0
- novastar_client-1.2.0/src/novastar_client/cli/settings.py +7 -0
- novastar_client-1.2.0/src/novastar_client/client.py +44 -0
- novastar_client-1.2.0/src/novastar_client/config.py +17 -0
- novastar_client-1.2.0/src/novastar_client/data/__init__.py +1 -0
- novastar_client-1.2.0/src/novastar_client/data/shef_parameters.csv +272 -0
- novastar_client-1.2.0/src/novastar_client/exceptions.py +56 -0
- novastar_client-1.2.0/src/novastar_client/logging_utils.py +29 -0
- novastar_client-1.2.0/src/novastar_client/models/__init__.py +25 -0
- novastar_client-1.2.0/src/novastar_client/models/datatype.py +45 -0
- novastar_client-1.2.0/src/novastar_client/models/datatype_response.py +68 -0
- novastar_client-1.2.0/src/novastar_client/models/meta.py +154 -0
- novastar_client-1.2.0/src/novastar_client/models/normalize_payload.py +33 -0
- novastar_client-1.2.0/src/novastar_client/models/station.py +69 -0
- novastar_client-1.2.0/src/novastar_client/models/station_response.py +60 -0
- novastar_client-1.2.0/src/novastar_client/models/timeseries.py +178 -0
- novastar_client-1.2.0/src/novastar_client/models/timeseries_response.py +143 -0
- novastar_client-1.2.0/src/novastar_client/models/tscatalog.py +132 -0
- novastar_client-1.2.0/src/novastar_client/models/tscatalog_response.py +91 -0
- novastar_client-1.2.0/src/novastar_client/services/__init__.py +13 -0
- novastar_client-1.2.0/src/novastar_client/services/datatype.py +77 -0
- novastar_client-1.2.0/src/novastar_client/services/station.py +51 -0
- novastar_client-1.2.0/src/novastar_client/services/timeseries.py +57 -0
- novastar_client-1.2.0/src/novastar_client/services/tscatalog.py +54 -0
- novastar_client-1.2.0/src/novastar_client/session.py +119 -0
- novastar_client-1.2.0/src/novastar_client/transform/__init__.py +7 -0
- novastar_client-1.2.0/src/novastar_client/transform/dss_data_type.py +64 -0
- novastar_client-1.2.0/src/novastar_client/transform/dss_time_interval.py +171 -0
- novastar_client-1.2.0/src/novastar_client/transform/shef_lookup.py +96 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: novastar-client
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Python client for NovaStar REST endpoints (Stations)
|
|
5
|
+
Author: Jeff Gregory
|
|
6
|
+
Author-email: Jeff Gregory <jeffrey.s.gregory@usace.army.mil>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Requires-Dist: requests>=2.31.0
|
|
9
|
+
Requires-Dist: click
|
|
10
|
+
Requires-Dist: pandas
|
|
11
|
+
Requires-Dist: hecdss
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Panama Canal Authority NovaStar API Client, novastar_client
|
|
16
|
+
|
|
17
|
+
## novastar_client
|
|
18
|
+
|
|
19
|
+
A Python client library for working with the NovaStar API, with documentation published via pdoc on GitHub pages. See [Releases](https://github.com/jeffsuperglide/novastar_client/releases) and the latest release for this package details and install guidance.
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
`novastar_client` is meant for developers who want to control or integrate NovaStar workflows from Python code instead of relying entirely on desktop tools. The documentation site is structured as API reference material, so the package is best approached as importable library for scripts, services, and internal utilities.
|
|
24
|
+
|
|
25
|
+
## What it includes
|
|
26
|
+
|
|
27
|
+
- A Python package under the `novastar_client` name, documented with pdoc.
|
|
28
|
+
- An API-first layout intended for code-based usage.
|
|
29
|
+
- Published release artifacts for installation from GitHub release pages.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Install from the repository's [Releases](https://github.com/jeffsuperglide/novastar_client/releases) using the package file provided on the GitHub release page. Release assets include a tarball and wheel. Download to install with pip, or install directly from the release version. It is suggested to use the wheel for installation because it will be a quicker install.
|
|
34
|
+
|
|
35
|
+
### pip install wheel, Windows CMD
|
|
36
|
+
|
|
37
|
+
```cmd
|
|
38
|
+
pip install .\novastar_client-0.1.0-py3-none-any.whl
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### pip install tarball, Windows CMD
|
|
42
|
+
|
|
43
|
+
```cmd
|
|
44
|
+
pip install .\novastar_client-0.1.0.tar.gz
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Direct pip install whl, Windows CMD
|
|
48
|
+
|
|
49
|
+
```cmd
|
|
50
|
+
pip install "https://github.com/jeffsuperglide/novastar_client/releases/download/v0.1.0/novastar_client-0.1.0-py3-none-any.whl"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
The full API reference is published at https://jeffsuperglide.github.io/novastar_client/. Reference for:
|
|
56
|
+
|
|
57
|
+
- Module and class names.
|
|
58
|
+
- Method signatures.
|
|
59
|
+
- Parmeter details.
|
|
60
|
+
- Return values.
|
|
61
|
+
|
|
62
|
+
## Reference Links
|
|
63
|
+
|
|
64
|
+
[API-UI](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/data/api/v1/api-ui)
|
|
65
|
+
|
|
66
|
+
[Operator Manual](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/doc/operator/user/)
|
|
67
|
+
|
|
68
|
+
[Operator Map](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/operator/map)
|
|
69
|
+
|
|
70
|
+
[Stations API Call - Simple](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/data/api/v1/stations)
|
|
71
|
+
|
|
72
|
+
[TriLynx NovaStar Web Services Docs Home](https://software.trilynx.systems/nsdataws/latest/doc-user/).
|
|
73
|
+
|
|
74
|
+
[Jython.org](https://www.jython.org/)
|
|
75
|
+
|
|
76
|
+
[Python 2.7](https://docs.python.org/2.7/)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Panama Canal Authority NovaStar API Client, novastar_client
|
|
2
|
+
|
|
3
|
+
## novastar_client
|
|
4
|
+
|
|
5
|
+
A Python client library for working with the NovaStar API, with documentation published via pdoc on GitHub pages. See [Releases](https://github.com/jeffsuperglide/novastar_client/releases) and the latest release for this package details and install guidance.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
`novastar_client` is meant for developers who want to control or integrate NovaStar workflows from Python code instead of relying entirely on desktop tools. The documentation site is structured as API reference material, so the package is best approached as importable library for scripts, services, and internal utilities.
|
|
10
|
+
|
|
11
|
+
## What it includes
|
|
12
|
+
|
|
13
|
+
- A Python package under the `novastar_client` name, documented with pdoc.
|
|
14
|
+
- An API-first layout intended for code-based usage.
|
|
15
|
+
- Published release artifacts for installation from GitHub release pages.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install from the repository's [Releases](https://github.com/jeffsuperglide/novastar_client/releases) using the package file provided on the GitHub release page. Release assets include a tarball and wheel. Download to install with pip, or install directly from the release version. It is suggested to use the wheel for installation because it will be a quicker install.
|
|
20
|
+
|
|
21
|
+
### pip install wheel, Windows CMD
|
|
22
|
+
|
|
23
|
+
```cmd
|
|
24
|
+
pip install .\novastar_client-0.1.0-py3-none-any.whl
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### pip install tarball, Windows CMD
|
|
28
|
+
|
|
29
|
+
```cmd
|
|
30
|
+
pip install .\novastar_client-0.1.0.tar.gz
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Direct pip install whl, Windows CMD
|
|
34
|
+
|
|
35
|
+
```cmd
|
|
36
|
+
pip install "https://github.com/jeffsuperglide/novastar_client/releases/download/v0.1.0/novastar_client-0.1.0-py3-none-any.whl"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
The full API reference is published at https://jeffsuperglide.github.io/novastar_client/. Reference for:
|
|
42
|
+
|
|
43
|
+
- Module and class names.
|
|
44
|
+
- Method signatures.
|
|
45
|
+
- Parmeter details.
|
|
46
|
+
- Return values.
|
|
47
|
+
|
|
48
|
+
## Reference Links
|
|
49
|
+
|
|
50
|
+
[API-UI](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/data/api/v1/api-ui)
|
|
51
|
+
|
|
52
|
+
[Operator Manual](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/doc/operator/user/)
|
|
53
|
+
|
|
54
|
+
[Operator Map](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/operator/map)
|
|
55
|
+
|
|
56
|
+
[Stations API Call - Simple](https://panama-cloud-ns5.trilynx-novastar.systems/novastar/data/api/v1/stations)
|
|
57
|
+
|
|
58
|
+
[TriLynx NovaStar Web Services Docs Home](https://software.trilynx.systems/nsdataws/latest/doc-user/).
|
|
59
|
+
|
|
60
|
+
[Jython.org](https://www.jython.org/)
|
|
61
|
+
|
|
62
|
+
[Python 2.7](https://docs.python.org/2.7/)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.12.5,<0.13"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "novastar-client"
|
|
7
|
+
version = "1.2.0"
|
|
8
|
+
description = "Python client for NovaStar REST endpoints (Stations)"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"requests>=2.31.0",
|
|
14
|
+
"click",
|
|
15
|
+
"pandas",
|
|
16
|
+
"hecdss",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[[project.authors]]
|
|
20
|
+
name = "Jeff Gregory"
|
|
21
|
+
email = "jeffrey.s.gregory@usace.army.mil"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
ns5acp = "novastar_client.cli.ns5acp:cli"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=7.0",
|
|
29
|
+
"pytest-cov>=4.0",
|
|
30
|
+
"mypy>=1.0",
|
|
31
|
+
"ruff>=0.4.0",
|
|
32
|
+
"pdocs",
|
|
33
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.12.5,<0.13"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "novastar-client"
|
|
7
|
+
version = "1.2.0"
|
|
8
|
+
description = "Python client for NovaStar REST endpoints (Stations)"
|
|
9
|
+
authors = [{ name = "Jeff Gregory", email = "jeffrey.s.gregory@usace.army.mil" }]
|
|
10
|
+
license = "MIT"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["requests>=2.31.0", "click", "pandas", "hecdss"]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
ns5acp = "novastar_client.cli.ns5acp:cli"
|
|
17
|
+
|
|
18
|
+
[dependency-groups]
|
|
19
|
+
dev = [
|
|
20
|
+
"pytest>=7.0",
|
|
21
|
+
"pytest-cov>=4.0",
|
|
22
|
+
"mypy>=1.0",
|
|
23
|
+
"ruff>=0.4.0",
|
|
24
|
+
"pdocs",
|
|
25
|
+
]
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# novastar-client
|
|
2
|
+
|
|
3
|
+
`novastar-client` is a Python client for NovaStar-style REST data endpoints exposed under paths like:
|
|
4
|
+
|
|
5
|
+
- `/novastar/data/api/v1/stations`
|
|
6
|
+
- `/novastar/data/api/v1/time-series`
|
|
7
|
+
- `/novastar/data/api/v1/ratings`
|
|
8
|
+
- `/novastar/data/api/v1/points`
|
|
9
|
+
- `/novastar/data/api/v1/general`
|
|
10
|
+
|
|
11
|
+
It provides:
|
|
12
|
+
|
|
13
|
+
- A version-aware client (`v1`, `v2`, etc.) using a configurable `api_version`
|
|
14
|
+
- Grouped services (Stations, Time Series, Ratings, Points, General)
|
|
15
|
+
- Typed models for resources (starting with Stations), including support for both `jsonFormat=full` and `jsonFormat=bare` response shapes
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Versioned API root**: Requests go to `/novastar/data/api/{api_version}/...` based on configuration.
|
|
21
|
+
- **Grouped endpoints**: Access resources via `client.stations`, `client.time_series`, `client.ratings`, `client.points`, and `client.general`.
|
|
22
|
+
- **Stations models**:
|
|
23
|
+
- `jsonFormat=bare`: top-level JSON is an array of station objects.
|
|
24
|
+
- `jsonFormat=full`: top-level JSON is an envelope with `apiVersion`, `attributionAndUsage`, `responseInfo`, and `stations`.
|
|
25
|
+
- **Editable install**: Designed for `pip install -e .` so you can iterate quickly while developing.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Installation (local editable)
|
|
29
|
+
|
|
30
|
+
Create a virtual environment and install the package in editable mode:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# from the repository root (where pyproject.toml lives)
|
|
34
|
+
python -m venv .venv
|
|
35
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
36
|
+
|
|
37
|
+
pip install --upgrade pip
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This will:
|
|
42
|
+
|
|
43
|
+
- Install `novastar-client` in editable mode
|
|
44
|
+
- Install dev tools like `pytest` (defined under `[project.optional-dependencies].dev` in `pyproject.toml`)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
The client configuration is defined via `NovaStarConfig`:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from novastar_client import NovaStarClient, NovaStarConfig
|
|
53
|
+
|
|
54
|
+
config = NovaStarConfig(
|
|
55
|
+
base_url="https://panama-cloud-ns5.trilynx-novastar.systems",
|
|
56
|
+
api_version="v1", # or "v2" when you support it
|
|
57
|
+
timeout=30,
|
|
58
|
+
verify_ssl=True,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
client = NovaStarClient(config)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Key options:
|
|
65
|
+
|
|
66
|
+
- `base_url`: Root of the NovaStar deployment
|
|
67
|
+
- `api_version`: Version segment used in the URL, e.g. `"v1"` → `/novastar/data/api/v1/...`
|
|
68
|
+
- `timeout`: Request timeout in seconds
|
|
69
|
+
- `verify_ssl`: SSL verification toggle
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Client structure
|
|
73
|
+
|
|
74
|
+
The top-level client wires a shared HTTP session into category-specific services:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from novastar_client import NovaStarClient, NovaStarConfig
|
|
78
|
+
|
|
79
|
+
client = NovaStarClient(NovaStarConfig(api_version="v1"))
|
|
80
|
+
|
|
81
|
+
# Services
|
|
82
|
+
stations_service = client.stations
|
|
83
|
+
# (time_series, ratings, points, general can be added similarly)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Stations API
|
|
88
|
+
|
|
89
|
+
The `StationsAPI` exposes a `list` method that maps directly to the `stations` endpoint and supports both `jsonFormat=full` and `jsonFormat=bare`.
|
|
90
|
+
|
|
91
|
+
### Parameters
|
|
92
|
+
|
|
93
|
+
The following query parameters are supported:
|
|
94
|
+
|
|
95
|
+
- `station_num_ids` → `stationNumId` (comma-separated list)
|
|
96
|
+
- `station_name` → `stationName` (supports `*` wildcard at start and/or end)
|
|
97
|
+
- `include_retired_stations` → `includeRetiredStations`
|
|
98
|
+
- `include_test_stations` → `includeTestStations`
|
|
99
|
+
- `debug` → `debug`
|
|
100
|
+
- `json_format` → `jsonFormat` (`"full"` or `"bare"`)
|
|
101
|
+
- `xml_format` → `xmlFormat`
|
|
102
|
+
- `format_pretty_print` → `formatPrettyPrint`
|
|
103
|
+
|
|
104
|
+
### jsonFormat=bare
|
|
105
|
+
|
|
106
|
+
When `json_format="bare"`, the endpoint returns a JSON array of station objects, and the client returns a `List[Station]`.
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from novastar_client import NovaStarClient, NovaStarConfig
|
|
110
|
+
|
|
111
|
+
client = NovaStarClient(NovaStarConfig(api_version="v1"))
|
|
112
|
+
|
|
113
|
+
stations = client.stations.list(
|
|
114
|
+
station_num_ids=,[1][2]
|
|
115
|
+
json_format="bare",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
for s in stations:
|
|
119
|
+
print(s.num_id, s.name, s.latitude, s.longitude)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`Station` fields (derived from the bare JSON) include:
|
|
123
|
+
|
|
124
|
+
- `id: int`
|
|
125
|
+
- `num_id: int` (from `numId`)
|
|
126
|
+
- `name: str`
|
|
127
|
+
- `description: Optional[str]`
|
|
128
|
+
- `description_text: Optional[str]`
|
|
129
|
+
- `dashboard_url: Optional[str]`
|
|
130
|
+
- `elevation: Optional[float]`
|
|
131
|
+
- `last_time_polled: Optional[str]`
|
|
132
|
+
- `latitude: Optional[float]`
|
|
133
|
+
- `longitude: Optional[float]`
|
|
134
|
+
- `out_of_service: Optional[bool]`
|
|
135
|
+
- `remote_tag: Optional[str]`
|
|
136
|
+
- `retired_station: Optional[bool]`
|
|
137
|
+
- `tag_name: Optional[str]`
|
|
138
|
+
- `test_station: Optional[bool]`
|
|
139
|
+
- `type_id: Optional[int]`
|
|
140
|
+
- `station_type_name: Optional[str]`
|
|
141
|
+
- `station_type_protocol: Optional[str]`
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### jsonFormat=full
|
|
145
|
+
|
|
146
|
+
When `json_format="full"`, the endpoint returns a structured envelope with version metadata, attribution/usage info, response info, and a `stations` array. The client returns a `StationsResponse` model.
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
resp = client.stations.list(
|
|
150
|
+
station_name="*PANAMA*",
|
|
151
|
+
json_format="full",
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
print(resp.api_version.api_dot_delimited_version)
|
|
155
|
+
print(resp.response_info.size)
|
|
156
|
+
for s in resp.stations:
|
|
157
|
+
print(s.num_id, s.name)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`StationsResponse` contains:
|
|
161
|
+
|
|
162
|
+
- `api_version: ApiVersion`
|
|
163
|
+
- `attribution_and_usage: AttributionAndUsage`
|
|
164
|
+
- `response_info: ResponseInfo`
|
|
165
|
+
- `stations: List[Station]`
|
|
166
|
+
|
|
167
|
+
This lets you access both the actual station data and useful metadata such as query timing, caching, and attribution requirements.
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## Models
|
|
171
|
+
|
|
172
|
+
Models live under `src/novastar_client/models/` and are responsible for mapping API JSON into typed Python objects.
|
|
173
|
+
|
|
174
|
+
Currently implemented:
|
|
175
|
+
|
|
176
|
+
- `Station`: one station record
|
|
177
|
+
- `StationsResponse`: full envelope for the stations endpoint
|
|
178
|
+
- `ApiVersion`, `AttributionAndUsage`, `ResponseInfo`: envelope metadata
|
|
179
|
+
|
|
180
|
+
Each model provides a `from_api` class method to construct it from a raw `dict`:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from novastar_client.models import Station, StationsResponse
|
|
184
|
+
|
|
185
|
+
station = Station.from_api(raw_station_dict)
|
|
186
|
+
stations_response = StationsResponse.from_api(raw_envelope_dict)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
## Running tests
|
|
191
|
+
|
|
192
|
+
Tests use `pytest` and mock the HTTP session so you can verify behavior without hitting a real NovaStar instance.
|
|
193
|
+
|
|
194
|
+
To run all tests:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
pytest
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Example: test for Stations API
|
|
201
|
+
|
|
202
|
+
The `tests/test_stations_api.py` file exercises both `jsonFormat=bare` and `jsonFormat=full` behavior:
|
|
203
|
+
|
|
204
|
+
- Ensures the correct query parameter (`jsonFormat`) is sent.
|
|
205
|
+
- Asserts that `json_format="bare"` returns a `List[Station]`.
|
|
206
|
+
- Asserts that `json_format="full"` returns a `StationsResponse`.
|
|
207
|
+
|
|
208
|
+
A simplified example:
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from typing import Any
|
|
212
|
+
from unittest.mock import MagicMock
|
|
213
|
+
|
|
214
|
+
from novastar_client import NovaStarClient, NovaStarConfig
|
|
215
|
+
from novastar_client.models import Station, StationsResponse
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def test_stations_list_bare_returns_station_models():
|
|
219
|
+
bare_payload = [
|
|
220
|
+
{
|
|
221
|
+
"id": 1,
|
|
222
|
+
"numId": 123,
|
|
223
|
+
"name": "TEST STATION",
|
|
224
|
+
"description": "",
|
|
225
|
+
"descriptionText": "",
|
|
226
|
+
"dashboardUrl": None,
|
|
227
|
+
"elevation": 10.5,
|
|
228
|
+
"lastTimePolled": "2024-01-01T00:00:00-05:00",
|
|
229
|
+
"latitude": 9.0,
|
|
230
|
+
"longitude": -79.5,
|
|
231
|
+
"outOfService": False,
|
|
232
|
+
"remoteTag": "123",
|
|
233
|
+
"retiredStation": False,
|
|
234
|
+
"tagName": "TST",
|
|
235
|
+
"testStation": False,
|
|
236
|
+
"typeId": 20,
|
|
237
|
+
"stationTypeName": "Campbell Scientific ALERT2 Radio",
|
|
238
|
+
"stationTypeProtocol": "ALERT2",
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
|
|
242
|
+
config = NovaStarConfig(api_version="v1")
|
|
243
|
+
client = NovaStarClient(config)
|
|
244
|
+
|
|
245
|
+
mock_get = MagicMock(return_value=bare_payload)
|
|
246
|
+
client.session.get = mock_get # type: ignore[attr-defined]
|
|
247
|
+
|
|
248
|
+
result = client.stations.list(json_format="bare")
|
|
249
|
+
|
|
250
|
+
assert isinstance(result, list)
|
|
251
|
+
assert isinstance(result, Station)
|
|
252
|
+
assert result.num_id == 123
|
|
253
|
+
assert result.name == "TEST STATION"
|
|
254
|
+
|
|
255
|
+
called_path, called_kwargs = mock_get.call_args
|
|
256
|
+
assert called_path == "stations"
|
|
257
|
+
assert called_kwargs["params"]["jsonFormat"] == "bare"
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def test_stations_list_full_returns_stations_response():
|
|
261
|
+
full_payload: dict[str, Any] = {
|
|
262
|
+
"apiVersion": {
|
|
263
|
+
"apiVersionMajor": "1",
|
|
264
|
+
"apiVersionMinor": "0",
|
|
265
|
+
"apiVersionMicro": "0",
|
|
266
|
+
"apiVersionModifier": "",
|
|
267
|
+
"apiVersionDate": "2024-01-01",
|
|
268
|
+
"apiVersionTime": "00:00:00",
|
|
269
|
+
"apiDotDelimitedVersion": "1.0.0",
|
|
270
|
+
},
|
|
271
|
+
"attributionAndUsage": {
|
|
272
|
+
"providerOrganizationText": "Test Org",
|
|
273
|
+
"providerOrganizationUri": "https://example.com",
|
|
274
|
+
"dataPolicyUri": "",
|
|
275
|
+
"disclaimerText": "",
|
|
276
|
+
"disclaimerUri": "",
|
|
277
|
+
"licenseText": "",
|
|
278
|
+
"licenseUri": "",
|
|
279
|
+
"usageConstraintsText": "",
|
|
280
|
+
"usageConstraintsUri": "",
|
|
281
|
+
"recommendedAttributionText": "",
|
|
282
|
+
},
|
|
283
|
+
"responseInfo": {
|
|
284
|
+
"urlOriginal": "https://example.com",
|
|
285
|
+
"urlOriginalEncoded": "",
|
|
286
|
+
"url": "",
|
|
287
|
+
"urlEncoded": "",
|
|
288
|
+
"periodStart": None,
|
|
289
|
+
"periodEnd": None,
|
|
290
|
+
"size": 1,
|
|
291
|
+
"queryStart": "2024-01-01T00:00:00Z",
|
|
292
|
+
"queryMs": 10,
|
|
293
|
+
"queryTargetMs": 50,
|
|
294
|
+
"queryTargetMet": True,
|
|
295
|
+
"isCached": False,
|
|
296
|
+
"cacheExpirationTime": None,
|
|
297
|
+
},
|
|
298
|
+
"stations": bare_payload,
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
config = NovaStarConfig(api_version="v1")
|
|
302
|
+
client = NovaStarClient(config)
|
|
303
|
+
|
|
304
|
+
mock_get = MagicMock(return_value=full_payload)
|
|
305
|
+
client.session.get = mock_get # type: ignore[attr-defined]
|
|
306
|
+
|
|
307
|
+
result = client.stations.list(json_format="full")
|
|
308
|
+
|
|
309
|
+
assert isinstance(result, StationsResponse)
|
|
310
|
+
assert result.api_version.api_dot_delimited_version == "1.0.0"
|
|
311
|
+
assert len(result.stations) == 1
|
|
312
|
+
assert result.stations.name == "TEST STATION"
|
|
313
|
+
|
|
314
|
+
called_path, called_kwargs = mock_get.call_args
|
|
315
|
+
assert called_path == "stations"
|
|
316
|
+
assert called_kwargs["params"]["jsonFormat"] == "full"
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
## Roadmap
|
|
321
|
+
|
|
322
|
+
- Add service modules and models for:
|
|
323
|
+
- Time Series
|
|
324
|
+
- Ratings
|
|
325
|
+
- Points
|
|
326
|
+
- General (health, info, etc.)
|
|
327
|
+
- Introduce version strategies for `v2` when the API contract diverges from `v1` while keeping the Python interface stable.
|
|
328
|
+
- Optional: add higher-level helpers (e.g., “get latest measurement for station X and point Y”) on top of the raw endpoints.
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
TBD (add your preferred license here).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Importing all the modules
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# __version__ = "1.0.0"
|
|
6
|
+
# my_package/__init__.py
|
|
7
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
8
|
+
|
|
9
|
+
from novastar_client import models
|
|
10
|
+
from novastar_client import services
|
|
11
|
+
from novastar_client import transform
|
|
12
|
+
|
|
13
|
+
from novastar_client.client import NovaStarClient
|
|
14
|
+
from novastar_client.config import NovaStarConfig
|
|
15
|
+
from novastar_client.session import NovaStarSession
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"models",
|
|
19
|
+
"services",
|
|
20
|
+
"transform",
|
|
21
|
+
"NovaStarClient",
|
|
22
|
+
"NovaStarConfig",
|
|
23
|
+
"NovaStarSession",
|
|
24
|
+
"cli", # type: ignore
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
__version__ = version("my-package")
|
|
29
|
+
except PackageNotFoundError:
|
|
30
|
+
__version__ = "v0.1.0" # or some sensible default
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""NovaStar Client command line interface subcommand, stations"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
import typing
|
|
8
|
+
import pprint
|
|
9
|
+
|
|
10
|
+
import click
|
|
11
|
+
|
|
12
|
+
from novastar_client.cli.helpers import output_pretty_json
|
|
13
|
+
|
|
14
|
+
from ..context import AppContext
|
|
15
|
+
from ..settings import CONTEXT_SETTINGS
|
|
16
|
+
from ...client import NovaStarClient
|
|
17
|
+
from ...config import NovaStarConfig
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
pass_app = click.make_pass_decorator(AppContext)
|
|
22
|
+
|
|
23
|
+
pp = pprint.PrettyPrinter(indent=4, width=80, compact=False)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@click.command(context_settings=CONTEXT_SETTINGS)
|
|
27
|
+
@click.option(
|
|
28
|
+
"--station-numid",
|
|
29
|
+
multiple=True,
|
|
30
|
+
help="Station numerical ID filter, using public identifiers, single "
|
|
31
|
+
"number or comma-separated list, can be repeated.",
|
|
32
|
+
)
|
|
33
|
+
@click.option(
|
|
34
|
+
"--pretty-print",
|
|
35
|
+
is_flag=True,
|
|
36
|
+
)
|
|
37
|
+
@pass_app
|
|
38
|
+
def stations(app: AppContext, station_numid: typing.Tuple, pretty_print: bool) -> None:
|
|
39
|
+
"""Subcommand returning a list of station metadata."""
|
|
40
|
+
|
|
41
|
+
config = NovaStarConfig(base_url=app.api_url, api_version=app.api_version)
|
|
42
|
+
client = NovaStarClient(config=config)
|
|
43
|
+
|
|
44
|
+
station_numbers = (
|
|
45
|
+
",".join(station_numid) if len(station_numid) > 1 else "".join(station_numid)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
resp = client.stations.get(stationNumId=station_numbers)
|
|
49
|
+
|
|
50
|
+
if resp is None:
|
|
51
|
+
logger.warning("Stations command line interface returned %s", resp)
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
resp_as_dict = resp.to_dict() # type: ignore
|
|
55
|
+
|
|
56
|
+
if pretty_print:
|
|
57
|
+
click.echo(output_pretty_json(resp_as_dict))
|
|
58
|
+
else:
|
|
59
|
+
click.echo(json.dumps(resp_as_dict))
|