meteostat-cli 0.3.0__tar.gz → 0.4.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.
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/PKG-INFO +33 -3
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/README.md +24 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/__init__.py +1 -1
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/cli.py +29 -3
- meteostat_cli-0.4.0/meteo/commands/contrib/__init__.py +44 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/add.py +171 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/build.py +48 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/delete.py +28 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/duplicates.py +64 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/edit.py +177 -0
- meteostat_cli-0.4.0/meteo/commands/contrib/validate.py +78 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/station.py +57 -12
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/config.py +3 -2
- meteostat_cli-0.4.0/meteo/contrib/__init__.py +4 -0
- meteostat_cli-0.4.0/meteo/contrib/database.py +103 -0
- meteostat_cli-0.4.0/meteo/contrib/duplicates.py +133 -0
- meteostat_cli-0.4.0/meteo/contrib/repo.py +181 -0
- meteostat_cli-0.4.0/meteo/contrib/validation.py +236 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/utils.py +6 -3
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/pyproject.toml +13 -2
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/conftest.py +4 -2
- meteostat_cli-0.4.0/tests/test_contrib.py +597 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/test_utils.py +8 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/uv.lock +440 -96
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/.claude/skills/meteo/SKILL.md +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/.github/workflows/lint.yml +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/.github/workflows/publish.yml +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/.github/workflows/test.yml +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/.gitignore +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/LICENSE +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/demo.gif +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/demo.yml +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/__init__.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/config.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/daily.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/hourly.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/inventory.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/monthly.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/nearby.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/commands/normals.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/meteo/plotting.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/__init__.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/test_cli.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/test_commands.py +0 -0
- {meteostat_cli-0.3.0 → meteostat_cli-0.4.0}/tests/test_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: meteostat-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Access weather and climate data through the terminal.
|
|
5
5
|
Project-URL: Homepage, https://github.com/meteostat/cli
|
|
6
6
|
Project-URL: Repository, https://github.com/meteostat/cli
|
|
@@ -18,11 +18,17 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
|
-
Requires-Dist: meteostat<3,>=2.1.
|
|
21
|
+
Requires-Dist: meteostat<3,>=2.1.5
|
|
22
22
|
Requires-Dist: pyyaml>=6.0
|
|
23
23
|
Requires-Dist: typer>=0.15.0
|
|
24
|
+
Provides-Extra: contrib
|
|
25
|
+
Requires-Dist: jsonschema>=4.20.0; extra == 'contrib'
|
|
26
|
+
Requires-Dist: pycountry>=24.6.1; extra == 'contrib'
|
|
24
27
|
Provides-Extra: plot
|
|
25
28
|
Requires-Dist: matplotlib>=3.9.0; extra == 'plot'
|
|
29
|
+
Provides-Extra: providers
|
|
30
|
+
Requires-Dist: lxml>=5.3.0; extra == 'providers'
|
|
31
|
+
Requires-Dist: metar>=1.11.0; extra == 'providers'
|
|
26
32
|
Description-Content-Type: text/markdown
|
|
27
33
|
|
|
28
34
|
<!-- PROJECT SHIELDS -->
|
|
@@ -72,6 +78,18 @@ For plotting capabilities (`png` and `svg` output), install the `plot` extra:
|
|
|
72
78
|
uv tool install "meteostat-cli[plot]"
|
|
73
79
|
```
|
|
74
80
|
|
|
81
|
+
To [contribute to the weather stations directory](https://dev.meteostat.net/cli/stations/contributing) using `meteo station add`, `edit`, `validate` and `build`, install the `contrib` extra:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
uv tool install "meteostat-cli[contrib]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For full provider support, use:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv tool install "meteostat-cli[providers]"
|
|
91
|
+
```
|
|
92
|
+
|
|
75
93
|
Alternatively, you can use `uvx`:
|
|
76
94
|
|
|
77
95
|
```bash
|
|
@@ -108,6 +126,18 @@ Please refer to the [official documentation](https://dev.meteostat.net/cli) for
|
|
|
108
126
|
|
|
109
127
|
Please read our [contributing guidelines](https://dev.meteostat.net/contributing) for details on how to contribute to Meteostat.
|
|
110
128
|
|
|
129
|
+
### Local Development
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
uv tool install --force -e ".[plot,contrib,providers]"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
You can now run the CLI locally using:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
meteo [YOUR_COMMAND]
|
|
139
|
+
```
|
|
140
|
+
|
|
111
141
|
## 📄 License
|
|
112
142
|
|
|
113
143
|
The Meteostat CLI is licensed under the [**MIT License**](https://github.com/meteostat/cli/blob/main/LICENSE). Data provided by Meteostat is licensed under [**Creative Commons Attribution 4.0 International (CC BY 4.0)**](https://creativecommons.org/licenses/by/4.0). See the [documentation](https://dev.meteostat.net/license) for details.
|
|
@@ -45,6 +45,18 @@ For plotting capabilities (`png` and `svg` output), install the `plot` extra:
|
|
|
45
45
|
uv tool install "meteostat-cli[plot]"
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
To [contribute to the weather stations directory](https://dev.meteostat.net/cli/stations/contributing) using `meteo station add`, `edit`, `validate` and `build`, install the `contrib` extra:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
uv tool install "meteostat-cli[contrib]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For full provider support, use:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uv tool install "meteostat-cli[providers]"
|
|
58
|
+
```
|
|
59
|
+
|
|
48
60
|
Alternatively, you can use `uvx`:
|
|
49
61
|
|
|
50
62
|
```bash
|
|
@@ -81,6 +93,18 @@ Please refer to the [official documentation](https://dev.meteostat.net/cli) for
|
|
|
81
93
|
|
|
82
94
|
Please read our [contributing guidelines](https://dev.meteostat.net/contributing) for details on how to contribute to Meteostat.
|
|
83
95
|
|
|
96
|
+
### Local Development
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv tool install --force -e ".[plot,contrib,providers]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
You can now run the CLI locally using:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
meteo [YOUR_COMMAND]
|
|
106
|
+
```
|
|
107
|
+
|
|
84
108
|
## 📄 License
|
|
85
109
|
|
|
86
110
|
The Meteostat CLI is licensed under the [**MIT License**](https://github.com/meteostat/cli/blob/main/LICENSE). Data provided by Meteostat is licensed under [**Creative Commons Attribution 4.0 International (CC BY 4.0)**](https://creativecommons.org/licenses/by/4.0). See the [documentation](https://dev.meteostat.net/license) for details.
|
|
@@ -35,20 +35,46 @@ def callback(
|
|
|
35
35
|
apply_config()
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
STATION_EPILOG = (
|
|
39
|
+
"Contributor commands: add, edit, delete, validate, duplicates, build. "
|
|
40
|
+
"Run 'meteo station COMMAND --help' for details."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
38
44
|
def _register_commands() -> None:
|
|
39
45
|
"""Register all command modules with the Typer app."""
|
|
40
46
|
from meteo.commands.config import config_cmd
|
|
47
|
+
from meteo.commands.contrib.add import add_cmd
|
|
48
|
+
from meteo.commands.contrib.build import build_cmd
|
|
49
|
+
from meteo.commands.contrib.delete import delete_cmd
|
|
50
|
+
from meteo.commands.contrib.duplicates import duplicates_cmd
|
|
51
|
+
from meteo.commands.contrib.edit import edit_cmd
|
|
52
|
+
from meteo.commands.contrib.validate import validate_cmd
|
|
41
53
|
from meteo.commands.daily import daily_cmd, daily_cmd_alias
|
|
42
54
|
from meteo.commands.hourly import hourly_cmd, hourly_cmd_alias
|
|
43
55
|
from meteo.commands.inventory import inventory_cmd, inventory_cmd_alias
|
|
44
56
|
from meteo.commands.monthly import monthly_cmd, monthly_cmd_alias
|
|
45
57
|
from meteo.commands.nearby import nearby_cmd
|
|
46
58
|
from meteo.commands.normals import normals_cmd, normals_cmd_alias
|
|
47
|
-
from meteo.commands.station import station_cmd
|
|
59
|
+
from meteo.commands.station import LookupCommand, StationGroup, station_cmd
|
|
60
|
+
|
|
61
|
+
station_app = typer.Typer(cls=StationGroup)
|
|
62
|
+
station_app.command(
|
|
63
|
+
StationGroup.default_command,
|
|
64
|
+
cls=LookupCommand,
|
|
65
|
+
hidden=True,
|
|
66
|
+
epilog=STATION_EPILOG,
|
|
67
|
+
)(station_cmd)
|
|
68
|
+
station_app.command("add")(add_cmd)
|
|
69
|
+
station_app.command("edit")(edit_cmd)
|
|
70
|
+
station_app.command("delete")(delete_cmd)
|
|
71
|
+
station_app.command("validate")(validate_cmd)
|
|
72
|
+
station_app.command("duplicates")(duplicates_cmd)
|
|
73
|
+
station_app.command("build")(build_cmd)
|
|
48
74
|
|
|
49
75
|
app.command("config")(config_cmd)
|
|
50
|
-
app.
|
|
51
|
-
app.
|
|
76
|
+
app.add_typer(station_app, name="station", help=station_cmd.__doc__)
|
|
77
|
+
app.add_typer(station_app, name="s", hidden=True)
|
|
52
78
|
app.command("nearby")(nearby_cmd)
|
|
53
79
|
app.command("inventory")(inventory_cmd)
|
|
54
80
|
app.command("i", hidden=True)(inventory_cmd_alias)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Contributor commands for the weather stations repository."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.contrib.validation import Report
|
|
8
|
+
|
|
9
|
+
REPO_HELP = "Path to the stations repository (overrides stations_repo)."
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def echo_report(report: Report, quiet: bool = False) -> None:
|
|
13
|
+
"""Print the validation result of a station."""
|
|
14
|
+
for error in report.errors:
|
|
15
|
+
typer.echo(f"{typer.style('✗', fg='red')} {report.station_id} {error}")
|
|
16
|
+
for warning in report.warnings:
|
|
17
|
+
typer.echo(f"{typer.style('!', fg='yellow')} {report.station_id} {warning}")
|
|
18
|
+
if report.valid and not report.warnings and not quiet:
|
|
19
|
+
typer.echo(f"{typer.style('✓', fg='green')} {report.station_id}")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def plural(count: int, word: str) -> str:
|
|
23
|
+
return f"{count} {word}" if count == 1 else f"{count} {word}s"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def print_station(data: dict[str, Any]) -> None:
|
|
27
|
+
"""Print a station record in the same way as `meteo station ID`."""
|
|
28
|
+
from meteo.commands.station import print_metadata
|
|
29
|
+
|
|
30
|
+
location = data.get("location") or {}
|
|
31
|
+
names = data.get("name") or {}
|
|
32
|
+
print_metadata(
|
|
33
|
+
{
|
|
34
|
+
"id": data.get("id"),
|
|
35
|
+
"name": names.get("en"),
|
|
36
|
+
"country": data.get("country"),
|
|
37
|
+
"region": data.get("region"),
|
|
38
|
+
"latitude": location.get("latitude"),
|
|
39
|
+
"longitude": location.get("longitude"),
|
|
40
|
+
"elevation": location.get("elevation"),
|
|
41
|
+
"timezone": data.get("timezone"),
|
|
42
|
+
**(data.get("identifiers") or {}),
|
|
43
|
+
}
|
|
44
|
+
)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Add station command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from meteo.commands.contrib import REPO_HELP, echo_report
|
|
9
|
+
from meteo.contrib.duplicates import find_duplicates
|
|
10
|
+
from meteo.contrib.repo import (
|
|
11
|
+
generate_id,
|
|
12
|
+
load_stations,
|
|
13
|
+
resolve_repo,
|
|
14
|
+
serialize,
|
|
15
|
+
station_path,
|
|
16
|
+
write_station,
|
|
17
|
+
)
|
|
18
|
+
from meteo.contrib.validation import Validator
|
|
19
|
+
|
|
20
|
+
LOCALIZED_NAME = re.compile(r"^([a-z]{2})=(.+)$")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_names(values: list[str]) -> dict[str, str]:
|
|
24
|
+
"""Parse --name values. `LANG=NAME` sets a localized name, anything else English."""
|
|
25
|
+
names = {}
|
|
26
|
+
for value in values:
|
|
27
|
+
match = LOCALIZED_NAME.match(value)
|
|
28
|
+
lang, name = match.groups() if match else ("en", value)
|
|
29
|
+
names[lang] = name.strip()
|
|
30
|
+
return names
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def parse_identifiers(values: list[str]) -> dict[str, str]:
|
|
34
|
+
"""Parse KEY=VALUE identifiers."""
|
|
35
|
+
identifiers = {}
|
|
36
|
+
for value in values:
|
|
37
|
+
key, sep, ident = value.partition("=")
|
|
38
|
+
if not sep or not key.strip() or not ident.strip():
|
|
39
|
+
raise typer.BadParameter(
|
|
40
|
+
f"Identifiers must be KEY=VALUE, got '{value}'.", param_hint="--id"
|
|
41
|
+
)
|
|
42
|
+
identifiers[key.strip().lower()] = ident.strip()
|
|
43
|
+
return identifiers
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def add_cmd(
|
|
47
|
+
name: list[str] | None = typer.Option(
|
|
48
|
+
None,
|
|
49
|
+
"--name",
|
|
50
|
+
"-n",
|
|
51
|
+
help="Station name. Use LANG=NAME for a localized name (repeatable).",
|
|
52
|
+
),
|
|
53
|
+
country: str | None = typer.Option(
|
|
54
|
+
None, "--country", "-c", help="ISO 3166-1 alpha-2 country code."
|
|
55
|
+
),
|
|
56
|
+
region: str | None = typer.Option(
|
|
57
|
+
None, "--region", help="ISO 3166-2 state or region code."
|
|
58
|
+
),
|
|
59
|
+
lat: float | None = typer.Option(None, "--lat", help="Latitude."),
|
|
60
|
+
lon: float | None = typer.Option(None, "--lon", help="Longitude."),
|
|
61
|
+
elevation: int | None = typer.Option(
|
|
62
|
+
None, "--elevation", "-e", help="Elevation in meters."
|
|
63
|
+
),
|
|
64
|
+
timezone: str | None = typer.Option(
|
|
65
|
+
None, "--timezone", "-t", help="IANA time zone (e.g. Europe/Berlin)."
|
|
66
|
+
),
|
|
67
|
+
identifier: list[str] | None = typer.Option(
|
|
68
|
+
None,
|
|
69
|
+
"--id",
|
|
70
|
+
"-i",
|
|
71
|
+
help="Station identifier as KEY=VALUE, e.g. wmo=10637 (repeatable).",
|
|
72
|
+
),
|
|
73
|
+
yes: bool = typer.Option(
|
|
74
|
+
False,
|
|
75
|
+
"--yes",
|
|
76
|
+
"-y",
|
|
77
|
+
help="Don't prompt. Fail on missing properties and skip duplicate confirmation.",
|
|
78
|
+
),
|
|
79
|
+
dry_run: bool = typer.Option(
|
|
80
|
+
False, "--dry-run", help="Print the resulting JSON without writing any file."
|
|
81
|
+
),
|
|
82
|
+
repo: str | None = typer.Option(None, "--repo", help=REPO_HELP),
|
|
83
|
+
) -> None:
|
|
84
|
+
"""Add a new weather station."""
|
|
85
|
+
repo_path = resolve_repo(repo)
|
|
86
|
+
|
|
87
|
+
names = parse_names(name or [])
|
|
88
|
+
identifiers = parse_identifiers(identifier or [])
|
|
89
|
+
|
|
90
|
+
if yes:
|
|
91
|
+
missing = [
|
|
92
|
+
option
|
|
93
|
+
for option, value in (
|
|
94
|
+
("--name", names.get("en")),
|
|
95
|
+
("--country", country),
|
|
96
|
+
("--lat", lat),
|
|
97
|
+
("--lon", lon),
|
|
98
|
+
("--elevation", elevation),
|
|
99
|
+
("--timezone", timezone),
|
|
100
|
+
)
|
|
101
|
+
if value is None
|
|
102
|
+
]
|
|
103
|
+
if missing:
|
|
104
|
+
typer.echo(f"Error: Missing option(s): {', '.join(missing)}", err=True)
|
|
105
|
+
raise typer.Exit(2)
|
|
106
|
+
else:
|
|
107
|
+
if "en" not in names:
|
|
108
|
+
names["en"] = typer.prompt("Name (English)").strip()
|
|
109
|
+
if country is None:
|
|
110
|
+
country = typer.prompt("Country (ISO 3166-1 alpha-2)")
|
|
111
|
+
if region is None:
|
|
112
|
+
region = typer.prompt(
|
|
113
|
+
"Region (ISO 3166-2, optional)", default="", show_default=False
|
|
114
|
+
)
|
|
115
|
+
if lat is None:
|
|
116
|
+
lat = typer.prompt("Latitude", type=float)
|
|
117
|
+
if lon is None:
|
|
118
|
+
lon = typer.prompt("Longitude", type=float)
|
|
119
|
+
if elevation is None:
|
|
120
|
+
elevation = typer.prompt("Elevation (m)", type=int)
|
|
121
|
+
if timezone is None:
|
|
122
|
+
timezone = typer.prompt("Time zone (e.g. Europe/Berlin)")
|
|
123
|
+
if not identifier:
|
|
124
|
+
value = typer.prompt(
|
|
125
|
+
"Identifiers (KEY=VALUE, comma-separated, optional)",
|
|
126
|
+
default="",
|
|
127
|
+
show_default=False,
|
|
128
|
+
)
|
|
129
|
+
identifiers = parse_identifiers(
|
|
130
|
+
[item for item in value.split(",") if item.strip()]
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
station_id = generate_id(repo_path)
|
|
134
|
+
data: dict[str, Any] = {
|
|
135
|
+
"id": station_id,
|
|
136
|
+
"name": dict(sorted(names.items())),
|
|
137
|
+
"country": (country or "").strip().upper(),
|
|
138
|
+
"region": region.strip().upper() if region and region.strip() else None,
|
|
139
|
+
"identifiers": identifiers,
|
|
140
|
+
"location": {"latitude": lat, "longitude": lon, "elevation": elevation},
|
|
141
|
+
"timezone": (timezone or "").strip(),
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
stations = load_stations(repo_path)
|
|
145
|
+
report = Validator(stations).validate(station_id, data)
|
|
146
|
+
if not report.valid:
|
|
147
|
+
echo_report(report)
|
|
148
|
+
raise typer.Exit(1)
|
|
149
|
+
|
|
150
|
+
stations[station_id] = data
|
|
151
|
+
duplicates = find_duplicates(stations, ids={station_id})
|
|
152
|
+
if duplicates:
|
|
153
|
+
typer.echo("Potential duplicates:", err=True)
|
|
154
|
+
for dup in duplicates:
|
|
155
|
+
other = dup.station_b if dup.station_a == station_id else dup.station_a
|
|
156
|
+
other_name = stations[other].get("name", {}).get("en", "")
|
|
157
|
+
dist = f"{dup.distance} m, " if dup.distance is not None else ""
|
|
158
|
+
typer.echo(
|
|
159
|
+
f" {other} {other_name} ({dist}{', '.join(dup.reasons)})",
|
|
160
|
+
err=True,
|
|
161
|
+
)
|
|
162
|
+
if not yes and not dry_run:
|
|
163
|
+
typer.confirm("Create station anyway?", abort=True, err=True)
|
|
164
|
+
|
|
165
|
+
if dry_run:
|
|
166
|
+
typer.echo(serialize(data))
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
path = station_path(repo_path, station_id)
|
|
170
|
+
write_station(path, data)
|
|
171
|
+
typer.echo(f"Created station {station_id} ({path.relative_to(repo_path)})")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Build station database command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.commands.contrib import REPO_HELP, echo_report, plural
|
|
8
|
+
from meteo.contrib.database import build_database
|
|
9
|
+
from meteo.contrib.repo import load_stations, resolve_repo, station_files
|
|
10
|
+
from meteo.contrib.validation import Validator
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_cmd(
|
|
14
|
+
output: str | None = typer.Option(
|
|
15
|
+
None,
|
|
16
|
+
"--output",
|
|
17
|
+
"-o",
|
|
18
|
+
help="Output file path (default: stations.db in the repository root).",
|
|
19
|
+
),
|
|
20
|
+
skip_validation: bool = typer.Option(
|
|
21
|
+
False, "--skip-validation", help="Don't validate stations before building."
|
|
22
|
+
),
|
|
23
|
+
repo: str | None = typer.Option(None, "--repo", help=REPO_HELP),
|
|
24
|
+
) -> None:
|
|
25
|
+
"""Build a SQLite database from the station files."""
|
|
26
|
+
repo_path = resolve_repo(repo)
|
|
27
|
+
output_path = Path(output).expanduser() if output else repo_path / "stations.db"
|
|
28
|
+
stations = load_stations(repo_path)
|
|
29
|
+
|
|
30
|
+
skipped = 0
|
|
31
|
+
if not skip_validation:
|
|
32
|
+
validator = Validator(stations)
|
|
33
|
+
for path in station_files(repo_path):
|
|
34
|
+
report = validator.validate_file(path)
|
|
35
|
+
if not report.valid:
|
|
36
|
+
echo_report(report, quiet=True)
|
|
37
|
+
stations.pop(path.stem, None)
|
|
38
|
+
skipped += 1
|
|
39
|
+
|
|
40
|
+
count, failed = build_database(stations, output_path)
|
|
41
|
+
for station_id, reason in failed:
|
|
42
|
+
typer.echo(f"{typer.style('✗', fg='red')} {station_id} {reason}")
|
|
43
|
+
|
|
44
|
+
skipped += len(failed)
|
|
45
|
+
summary = f"Built {output_path} with {plural(count, 'station')}"
|
|
46
|
+
if skipped:
|
|
47
|
+
summary += f" ({skipped} skipped)"
|
|
48
|
+
typer.echo(summary)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Delete station command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from meteo.commands.contrib import REPO_HELP, print_station
|
|
6
|
+
from meteo.contrib.repo import read_station, require_station, resolve_repo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def delete_cmd(
|
|
10
|
+
station_id: str = typer.Argument(..., help="Meteostat station ID."),
|
|
11
|
+
yes: bool = typer.Option(
|
|
12
|
+
False, "--yes", "-y", help="Skip the confirmation prompt."
|
|
13
|
+
),
|
|
14
|
+
repo: str | None = typer.Option(None, "--repo", help=REPO_HELP),
|
|
15
|
+
) -> None:
|
|
16
|
+
"""Remove a weather station."""
|
|
17
|
+
repo_path = resolve_repo(repo)
|
|
18
|
+
path = require_station(repo_path, station_id)
|
|
19
|
+
|
|
20
|
+
if not yes:
|
|
21
|
+
try:
|
|
22
|
+
print_station(read_station(path))
|
|
23
|
+
except ValueError:
|
|
24
|
+
typer.echo(f"Warning: {path.name} contains invalid JSON.", err=True)
|
|
25
|
+
typer.confirm(f"Delete station {path.stem}?", abort=True)
|
|
26
|
+
|
|
27
|
+
path.unlink()
|
|
28
|
+
typer.echo(f"Deleted station {path.stem} ({path.relative_to(repo_path)})")
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Find duplicate stations command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
from meteo.commands.contrib import REPO_HELP
|
|
7
|
+
from meteo.contrib.duplicates import find_duplicates
|
|
8
|
+
from meteo.contrib.repo import load_stations, resolve_repo
|
|
9
|
+
from meteo.utils import detect_format, output_df
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def duplicates_cmd(
|
|
13
|
+
station_ids: list[str] | None = typer.Option(
|
|
14
|
+
None, "--id", help="Only report duplicates of the given station (repeatable)."
|
|
15
|
+
),
|
|
16
|
+
country: str | None = typer.Option(
|
|
17
|
+
None, "--country", "-c", help="Only check stations in the given country."
|
|
18
|
+
),
|
|
19
|
+
radius: int = typer.Option(
|
|
20
|
+
1000, "--radius", "-r", help="Maximum distance in meters for location matches."
|
|
21
|
+
),
|
|
22
|
+
fmt: str | None = typer.Option(None, "--format", "-f", help="Output format."),
|
|
23
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
24
|
+
no_header: bool = typer.Option(
|
|
25
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
26
|
+
),
|
|
27
|
+
show_all: bool = typer.Option(
|
|
28
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
29
|
+
),
|
|
30
|
+
repo: str | None = typer.Option(None, "--repo", help=REPO_HELP),
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Find potential duplicate stations."""
|
|
33
|
+
repo_path = resolve_repo(repo)
|
|
34
|
+
stations = load_stations(repo_path)
|
|
35
|
+
|
|
36
|
+
if country:
|
|
37
|
+
stations = {
|
|
38
|
+
station_id: data
|
|
39
|
+
for station_id, data in stations.items()
|
|
40
|
+
if str(data.get("country", "")).upper() == country.upper()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ids = {station_id.upper() for station_id in station_ids} if station_ids else None
|
|
44
|
+
duplicates = find_duplicates(stations, radius=radius, ids=ids)
|
|
45
|
+
|
|
46
|
+
if not duplicates:
|
|
47
|
+
typer.echo("No potential duplicates found.", err=True)
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
df = pd.DataFrame(
|
|
51
|
+
[
|
|
52
|
+
{
|
|
53
|
+
"station_a": dup.station_a,
|
|
54
|
+
"station_b": dup.station_b,
|
|
55
|
+
"distance": dup.distance,
|
|
56
|
+
"reasons": ", ".join(dup.reasons),
|
|
57
|
+
}
|
|
58
|
+
for dup in duplicates
|
|
59
|
+
]
|
|
60
|
+
).set_index(["station_a", "station_b"])
|
|
61
|
+
|
|
62
|
+
actual_fmt = detect_format(fmt, output)
|
|
63
|
+
output_df(df, actual_fmt, output, no_header, show_all=show_all)
|
|
64
|
+
raise typer.Exit(1)
|