meteo-lt-pkg 0.2.4__tar.gz → 0.4.0b1__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.
- meteo_lt_pkg-0.4.0b1/PKG-INFO +324 -0
- meteo_lt_pkg-0.4.0b1/README.md +297 -0
- meteo_lt_pkg-0.4.0b1/meteo_lt/__init__.py +13 -0
- meteo_lt_pkg-0.4.0b1/meteo_lt/api.py +94 -0
- meteo_lt_pkg-0.4.0b1/meteo_lt/client.py +80 -0
- meteo_lt_pkg-0.4.0b1/meteo_lt/const.py +108 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt/models.py +28 -35
- meteo_lt_pkg-0.4.0b1/meteo_lt/warnings.py +183 -0
- meteo_lt_pkg-0.4.0b1/meteo_lt_pkg.egg-info/PKG-INFO +324 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt_pkg.egg-info/SOURCES.txt +3 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/pyproject.toml +1 -1
- meteo_lt_pkg-0.2.4/PKG-INFO +0 -178
- meteo_lt_pkg-0.2.4/README.md +0 -152
- meteo_lt_pkg-0.2.4/meteo_lt/__init__.py +0 -6
- meteo_lt_pkg-0.2.4/meteo_lt/api.py +0 -47
- meteo_lt_pkg-0.2.4/meteo_lt_pkg.egg-info/PKG-INFO +0 -178
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/LICENSE +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/MANIFEST.in +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt/utils.py +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt_pkg.egg-info/dependency_links.txt +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt_pkg.egg-info/requires.txt +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/meteo_lt_pkg.egg-info/top_level.txt +0 -0
- {meteo_lt_pkg-0.2.4 → meteo_lt_pkg-0.4.0b1}/setup.cfg +0 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meteo_lt-pkg
|
|
3
|
+
Version: 0.4.0b1
|
|
4
|
+
Summary: A library to fetch weather data from api.meteo.lt
|
|
5
|
+
Author-email: Brunas <brunonas@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/Brunas/meteo_lt-pkg
|
|
7
|
+
Project-URL: Issues, https://github.com/Brunas/meteo_lt-pkg/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
20
|
+
Requires-Dist: black; extra == "dev"
|
|
21
|
+
Requires-Dist: coverage; extra == "dev"
|
|
22
|
+
Requires-Dist: flake8; extra == "dev"
|
|
23
|
+
Requires-Dist: pyflakes; extra == "dev"
|
|
24
|
+
Requires-Dist: pylint; extra == "dev"
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# Meteo.Lt Lithuanian weather forecast package
|
|
29
|
+
|
|
30
|
+
[![GitHub Release][releases-shield]][releases]
|
|
31
|
+
[![GitHub Activity][commits-shield]][commits]
|
|
32
|
+
[![License][license-shield]](LICENSE)
|
|
33
|
+
![Project Maintenance][maintenance-shield]
|
|
34
|
+
[](https://github.com/psf/black)
|
|
35
|
+
|
|
36
|
+
<a href="https://buymeacoffee.com/pdfdc52z8h" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 40px !important;width: 145px !important;" ></a>
|
|
37
|
+
|
|
38
|
+
MeteoLt-Pkg is a Python library designed to fetch weather data from [`api.meteo.lt`](https://api.meteo.lt/). This library provides convenient methods to interact with the API and obtain weather forecasts and related data. Please visit for more information.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
You can install the package using pip:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install meteo_lt-pkg
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
Here's a quick example to get you started:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
from meteo_lt import MeteoLtAPI
|
|
55
|
+
|
|
56
|
+
async def quick_example():
|
|
57
|
+
async with MeteoLtAPI() as api:
|
|
58
|
+
# Get current weather for Vilnius
|
|
59
|
+
forecast = await api.get_forecast("vilnius")
|
|
60
|
+
current = forecast.current_conditions
|
|
61
|
+
|
|
62
|
+
print(f"Current temperature in Vilnius: {current.temperature}°C")
|
|
63
|
+
print(f"Condition: {current.condition_code}")
|
|
64
|
+
print(f"Wind: {current.wind_speed} m/s")
|
|
65
|
+
|
|
66
|
+
# Check for weather warnings
|
|
67
|
+
warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
68
|
+
if warnings:
|
|
69
|
+
print(f"Active warnings: {len(warnings)}")
|
|
70
|
+
for warning in warnings:
|
|
71
|
+
print(f" - {warning.warning_type}: {warning.severity}")
|
|
72
|
+
else:
|
|
73
|
+
print("No active weather warnings")
|
|
74
|
+
|
|
75
|
+
asyncio.run(quick_example())
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Basic Usage (Recommended)
|
|
81
|
+
|
|
82
|
+
The recommended way to use the library is with the `async with` context manager, which ensures proper cleanup of HTTP sessions:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import asyncio
|
|
86
|
+
from meteo_lt import MeteoLtAPI
|
|
87
|
+
|
|
88
|
+
async def main():
|
|
89
|
+
async with MeteoLtAPI() as api:
|
|
90
|
+
# Get weather forecast for Vilnius
|
|
91
|
+
forecast = await api.get_forecast("vilnius")
|
|
92
|
+
print(f"Current temperature in {forecast.place.name}: {forecast.current_conditions.temperature}°C")
|
|
93
|
+
|
|
94
|
+
# Get weather warnings for Vilnius
|
|
95
|
+
warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
96
|
+
print(f"Active warnings: {len(warnings)}")
|
|
97
|
+
for warning in warnings:
|
|
98
|
+
print(f"- {warning.warning_type}: {warning.description}")
|
|
99
|
+
|
|
100
|
+
asyncio.run(main())
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Alternative Usage
|
|
104
|
+
|
|
105
|
+
If you prefer not to use the context manager, make sure to call `close()` to properly cleanup resources:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
async def alternative_usage():
|
|
109
|
+
api = MeteoLtAPI()
|
|
110
|
+
try:
|
|
111
|
+
forecast = await api.get_forecast("kaunas")
|
|
112
|
+
print(f"Temperature: {forecast.current_conditions.temperature}°C")
|
|
113
|
+
finally:
|
|
114
|
+
await api.close() # Important: prevents session warnings
|
|
115
|
+
|
|
116
|
+
asyncio.run(alternative_usage())
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Fetching Places
|
|
120
|
+
|
|
121
|
+
To get the list of available places:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
async def fetch_places():
|
|
125
|
+
async with MeteoLtAPI() as api:
|
|
126
|
+
await api.fetch_places()
|
|
127
|
+
for place in api.places:
|
|
128
|
+
print(f"{place.name} ({place.code})")
|
|
129
|
+
|
|
130
|
+
asyncio.run(fetch_places())
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Getting the Nearest Place
|
|
134
|
+
|
|
135
|
+
You can find the nearest place using latitude and longitude coordinates:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
async def find_nearest_place():
|
|
139
|
+
async with MeteoLtAPI() as api:
|
|
140
|
+
# Example coordinates for Vilnius, Lithuania
|
|
141
|
+
nearest_place = await api.get_nearest_place(54.6872, 25.2797)
|
|
142
|
+
print(f"Nearest place: {nearest_place.name}")
|
|
143
|
+
|
|
144
|
+
asyncio.run(find_nearest_place())
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
> **NOTE**: If no places are retrieved before, that is done automatically in `get_nearest_place` method.
|
|
148
|
+
|
|
149
|
+
### Fetching Weather Forecast
|
|
150
|
+
|
|
151
|
+
To get the weather forecast for a specific place:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
async def fetch_forecast():
|
|
155
|
+
async with MeteoLtAPI() as api:
|
|
156
|
+
# Get forecast for Vilnius
|
|
157
|
+
forecast = await api.get_forecast("vilnius")
|
|
158
|
+
|
|
159
|
+
# Current conditions
|
|
160
|
+
current = forecast.current_conditions
|
|
161
|
+
print(f"Current temperature: {current.temperature}°C")
|
|
162
|
+
print(f"Feels like: {current.apparent_temperature}°C")
|
|
163
|
+
print(f"Condition: {current.condition_code}")
|
|
164
|
+
|
|
165
|
+
# Future forecasts
|
|
166
|
+
print(f"\nNext 24 hours:")
|
|
167
|
+
for timestamp in forecast.forecast_timestamps[:24]:
|
|
168
|
+
print(f"{timestamp.datetime}: {timestamp.temperature}°C")
|
|
169
|
+
|
|
170
|
+
asyncio.run(fetch_forecast())
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
> **NOTE**: `current_conditions` is the current hour record from the `forecast_timestamps` array. Also, `forecast_timestamps` array has past time records filtered out due to `api.meteo.lt` not doing that automatically.
|
|
174
|
+
|
|
175
|
+
### Fetching Weather Forecast with Warnings
|
|
176
|
+
|
|
177
|
+
To get weather forecast enriched with warnings:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
async def fetch_forecast_with_warnings():
|
|
181
|
+
async with MeteoLtAPI() as api:
|
|
182
|
+
# Get forecast with warnings using coordinates
|
|
183
|
+
forecast = await api.get_forecast_with_warnings(
|
|
184
|
+
latitude=54.6872,
|
|
185
|
+
longitude=25.2797
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
print(f"Forecast for {forecast.place.name}")
|
|
189
|
+
print(f"Current temperature: {forecast.current_conditions.temperature}°C")
|
|
190
|
+
|
|
191
|
+
# Check for warnings in current conditions
|
|
192
|
+
if forecast.current_conditions.warnings:
|
|
193
|
+
print("Current warnings:")
|
|
194
|
+
for warning in forecast.current_conditions.warnings:
|
|
195
|
+
print(f"- {warning.warning_type}: {warning.severity}")
|
|
196
|
+
|
|
197
|
+
asyncio.run(fetch_forecast_with_warnings())
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Fetching Weather Warnings
|
|
201
|
+
|
|
202
|
+
To get weather warnings for Lithuania or specific administrative areas:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
async def fetch_warnings():
|
|
206
|
+
async with MeteoLtAPI() as api:
|
|
207
|
+
# Get all weather warnings
|
|
208
|
+
warnings = await api.get_weather_warnings()
|
|
209
|
+
print(f"Total active warnings: {len(warnings)}")
|
|
210
|
+
|
|
211
|
+
for warning in warnings:
|
|
212
|
+
print(f"Warning: {warning.warning_type} in {warning.county}")
|
|
213
|
+
print(f"Severity: {warning.severity}")
|
|
214
|
+
print(f"Description: {warning.description}")
|
|
215
|
+
print(f"Active: {warning.start_time} to {warning.end_time}")
|
|
216
|
+
print("-" * 50)
|
|
217
|
+
|
|
218
|
+
async def fetch_warnings_for_area():
|
|
219
|
+
async with MeteoLtAPI() as api:
|
|
220
|
+
# Get warnings for specific administrative division
|
|
221
|
+
vilnius_warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
222
|
+
print(f"Warnings for Vilnius: {len(vilnius_warnings)}")
|
|
223
|
+
|
|
224
|
+
for warning in vilnius_warnings:
|
|
225
|
+
print(f"- {warning.warning_type} ({warning.severity})")
|
|
226
|
+
|
|
227
|
+
asyncio.run(fetch_warnings())
|
|
228
|
+
asyncio.run(fetch_warnings_for_area())
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Data Models
|
|
232
|
+
|
|
233
|
+
The package includes several data models to represent the API responses:
|
|
234
|
+
|
|
235
|
+
### Coordinates
|
|
236
|
+
|
|
237
|
+
Represents geographic coordinates.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from meteo_lt import Coordinates
|
|
241
|
+
|
|
242
|
+
coords = Coordinates(latitude=54.6872, longitude=25.2797)
|
|
243
|
+
print(coords)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Place
|
|
247
|
+
|
|
248
|
+
Represents a place with associated metadata.
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from meteo_lt import Place
|
|
252
|
+
|
|
253
|
+
place = Place(code="vilnius", name="Vilnius", administrative_division="Vilnius City Municipality", country="LT", coordinates=coords)
|
|
254
|
+
print(place.latitude, place.longitude)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### ForecastTimestamp
|
|
258
|
+
|
|
259
|
+
Represents a timestamp within the weather forecast, including various weather parameters.
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from meteo_lt import ForecastTimestamp
|
|
263
|
+
|
|
264
|
+
forecast_timestamp = ForecastTimestamp(
|
|
265
|
+
datetime="2024-07-23T12:00:00+00:00",
|
|
266
|
+
temperature=25.5,
|
|
267
|
+
apparent_temperature=27.0,
|
|
268
|
+
condition_code="clear",
|
|
269
|
+
wind_speed=5.0,
|
|
270
|
+
wind_gust_speed=8.0,
|
|
271
|
+
wind_bearing=180,
|
|
272
|
+
cloud_coverage=20,
|
|
273
|
+
pressure=1012,
|
|
274
|
+
humidity=60,
|
|
275
|
+
precipitation=0
|
|
276
|
+
)
|
|
277
|
+
print(forecast_timestamp.condition)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Forecast
|
|
281
|
+
|
|
282
|
+
Represents the weather forecast for a place, containing multiple forecast timestamps.
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
from meteo_lt import Forecast
|
|
286
|
+
|
|
287
|
+
forecast = Forecast(
|
|
288
|
+
place=place,
|
|
289
|
+
forecast_created=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
290
|
+
forecast_timestamps=[forecast_timestamp]
|
|
291
|
+
)
|
|
292
|
+
print(forecast.current_conditions().temperature)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### WeatherWarning
|
|
296
|
+
|
|
297
|
+
Represents a weather warning for a specific area.
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
from meteo_lt import WeatherWarning
|
|
301
|
+
|
|
302
|
+
warning = WeatherWarning(
|
|
303
|
+
county="Vilniaus apskritis",
|
|
304
|
+
warning_type="frost",
|
|
305
|
+
severity="Moderate",
|
|
306
|
+
description="Ground surface frost 0-5 degrees in many places",
|
|
307
|
+
start_time="2024-07-23T12:00:00Z",
|
|
308
|
+
end_time="2024-07-23T18:00:00Z"
|
|
309
|
+
)
|
|
310
|
+
print(f"Warning for {warning.county}: {warning.description}")
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Contributing
|
|
314
|
+
|
|
315
|
+
Contributions are welcome! For major changes please open an issue to discuss or submit a pull request with your changes. If you want to contribute you can use devcontainers in vscode for easiest setup follow [instructions here](.devcontainer/README.md).
|
|
316
|
+
|
|
317
|
+
***
|
|
318
|
+
|
|
319
|
+
[commits-shield]: https://img.shields.io/github/commit-activity/y/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
320
|
+
[commits]: https://github.com/Brunas/meteo_lt-pkg/commits/main
|
|
321
|
+
[license-shield]: https://img.shields.io/github/license/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
322
|
+
[maintenance-shield]: https://img.shields.io/badge/maintainer-Brunas%20%40Brunas-blue.svg?style=flat-square
|
|
323
|
+
[releases-shield]: https://img.shields.io/github/release/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
324
|
+
[releases]: https://github.com/Brunas/meteo_lt-pkg/releases
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Meteo.Lt Lithuanian weather forecast package
|
|
2
|
+
|
|
3
|
+
[![GitHub Release][releases-shield]][releases]
|
|
4
|
+
[![GitHub Activity][commits-shield]][commits]
|
|
5
|
+
[![License][license-shield]](LICENSE)
|
|
6
|
+
![Project Maintenance][maintenance-shield]
|
|
7
|
+
[](https://github.com/psf/black)
|
|
8
|
+
|
|
9
|
+
<a href="https://buymeacoffee.com/pdfdc52z8h" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 40px !important;width: 145px !important;" ></a>
|
|
10
|
+
|
|
11
|
+
MeteoLt-Pkg is a Python library designed to fetch weather data from [`api.meteo.lt`](https://api.meteo.lt/). This library provides convenient methods to interact with the API and obtain weather forecasts and related data. Please visit for more information.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
You can install the package using pip:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install meteo_lt-pkg
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Here's a quick example to get you started:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import asyncio
|
|
27
|
+
from meteo_lt import MeteoLtAPI
|
|
28
|
+
|
|
29
|
+
async def quick_example():
|
|
30
|
+
async with MeteoLtAPI() as api:
|
|
31
|
+
# Get current weather for Vilnius
|
|
32
|
+
forecast = await api.get_forecast("vilnius")
|
|
33
|
+
current = forecast.current_conditions
|
|
34
|
+
|
|
35
|
+
print(f"Current temperature in Vilnius: {current.temperature}°C")
|
|
36
|
+
print(f"Condition: {current.condition_code}")
|
|
37
|
+
print(f"Wind: {current.wind_speed} m/s")
|
|
38
|
+
|
|
39
|
+
# Check for weather warnings
|
|
40
|
+
warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
41
|
+
if warnings:
|
|
42
|
+
print(f"Active warnings: {len(warnings)}")
|
|
43
|
+
for warning in warnings:
|
|
44
|
+
print(f" - {warning.warning_type}: {warning.severity}")
|
|
45
|
+
else:
|
|
46
|
+
print("No active weather warnings")
|
|
47
|
+
|
|
48
|
+
asyncio.run(quick_example())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### Basic Usage (Recommended)
|
|
54
|
+
|
|
55
|
+
The recommended way to use the library is with the `async with` context manager, which ensures proper cleanup of HTTP sessions:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import asyncio
|
|
59
|
+
from meteo_lt import MeteoLtAPI
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
async with MeteoLtAPI() as api:
|
|
63
|
+
# Get weather forecast for Vilnius
|
|
64
|
+
forecast = await api.get_forecast("vilnius")
|
|
65
|
+
print(f"Current temperature in {forecast.place.name}: {forecast.current_conditions.temperature}°C")
|
|
66
|
+
|
|
67
|
+
# Get weather warnings for Vilnius
|
|
68
|
+
warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
69
|
+
print(f"Active warnings: {len(warnings)}")
|
|
70
|
+
for warning in warnings:
|
|
71
|
+
print(f"- {warning.warning_type}: {warning.description}")
|
|
72
|
+
|
|
73
|
+
asyncio.run(main())
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Alternative Usage
|
|
77
|
+
|
|
78
|
+
If you prefer not to use the context manager, make sure to call `close()` to properly cleanup resources:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
async def alternative_usage():
|
|
82
|
+
api = MeteoLtAPI()
|
|
83
|
+
try:
|
|
84
|
+
forecast = await api.get_forecast("kaunas")
|
|
85
|
+
print(f"Temperature: {forecast.current_conditions.temperature}°C")
|
|
86
|
+
finally:
|
|
87
|
+
await api.close() # Important: prevents session warnings
|
|
88
|
+
|
|
89
|
+
asyncio.run(alternative_usage())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Fetching Places
|
|
93
|
+
|
|
94
|
+
To get the list of available places:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
async def fetch_places():
|
|
98
|
+
async with MeteoLtAPI() as api:
|
|
99
|
+
await api.fetch_places()
|
|
100
|
+
for place in api.places:
|
|
101
|
+
print(f"{place.name} ({place.code})")
|
|
102
|
+
|
|
103
|
+
asyncio.run(fetch_places())
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Getting the Nearest Place
|
|
107
|
+
|
|
108
|
+
You can find the nearest place using latitude and longitude coordinates:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
async def find_nearest_place():
|
|
112
|
+
async with MeteoLtAPI() as api:
|
|
113
|
+
# Example coordinates for Vilnius, Lithuania
|
|
114
|
+
nearest_place = await api.get_nearest_place(54.6872, 25.2797)
|
|
115
|
+
print(f"Nearest place: {nearest_place.name}")
|
|
116
|
+
|
|
117
|
+
asyncio.run(find_nearest_place())
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
> **NOTE**: If no places are retrieved before, that is done automatically in `get_nearest_place` method.
|
|
121
|
+
|
|
122
|
+
### Fetching Weather Forecast
|
|
123
|
+
|
|
124
|
+
To get the weather forecast for a specific place:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
async def fetch_forecast():
|
|
128
|
+
async with MeteoLtAPI() as api:
|
|
129
|
+
# Get forecast for Vilnius
|
|
130
|
+
forecast = await api.get_forecast("vilnius")
|
|
131
|
+
|
|
132
|
+
# Current conditions
|
|
133
|
+
current = forecast.current_conditions
|
|
134
|
+
print(f"Current temperature: {current.temperature}°C")
|
|
135
|
+
print(f"Feels like: {current.apparent_temperature}°C")
|
|
136
|
+
print(f"Condition: {current.condition_code}")
|
|
137
|
+
|
|
138
|
+
# Future forecasts
|
|
139
|
+
print(f"\nNext 24 hours:")
|
|
140
|
+
for timestamp in forecast.forecast_timestamps[:24]:
|
|
141
|
+
print(f"{timestamp.datetime}: {timestamp.temperature}°C")
|
|
142
|
+
|
|
143
|
+
asyncio.run(fetch_forecast())
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> **NOTE**: `current_conditions` is the current hour record from the `forecast_timestamps` array. Also, `forecast_timestamps` array has past time records filtered out due to `api.meteo.lt` not doing that automatically.
|
|
147
|
+
|
|
148
|
+
### Fetching Weather Forecast with Warnings
|
|
149
|
+
|
|
150
|
+
To get weather forecast enriched with warnings:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
async def fetch_forecast_with_warnings():
|
|
154
|
+
async with MeteoLtAPI() as api:
|
|
155
|
+
# Get forecast with warnings using coordinates
|
|
156
|
+
forecast = await api.get_forecast_with_warnings(
|
|
157
|
+
latitude=54.6872,
|
|
158
|
+
longitude=25.2797
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
print(f"Forecast for {forecast.place.name}")
|
|
162
|
+
print(f"Current temperature: {forecast.current_conditions.temperature}°C")
|
|
163
|
+
|
|
164
|
+
# Check for warnings in current conditions
|
|
165
|
+
if forecast.current_conditions.warnings:
|
|
166
|
+
print("Current warnings:")
|
|
167
|
+
for warning in forecast.current_conditions.warnings:
|
|
168
|
+
print(f"- {warning.warning_type}: {warning.severity}")
|
|
169
|
+
|
|
170
|
+
asyncio.run(fetch_forecast_with_warnings())
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Fetching Weather Warnings
|
|
174
|
+
|
|
175
|
+
To get weather warnings for Lithuania or specific administrative areas:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
async def fetch_warnings():
|
|
179
|
+
async with MeteoLtAPI() as api:
|
|
180
|
+
# Get all weather warnings
|
|
181
|
+
warnings = await api.get_weather_warnings()
|
|
182
|
+
print(f"Total active warnings: {len(warnings)}")
|
|
183
|
+
|
|
184
|
+
for warning in warnings:
|
|
185
|
+
print(f"Warning: {warning.warning_type} in {warning.county}")
|
|
186
|
+
print(f"Severity: {warning.severity}")
|
|
187
|
+
print(f"Description: {warning.description}")
|
|
188
|
+
print(f"Active: {warning.start_time} to {warning.end_time}")
|
|
189
|
+
print("-" * 50)
|
|
190
|
+
|
|
191
|
+
async def fetch_warnings_for_area():
|
|
192
|
+
async with MeteoLtAPI() as api:
|
|
193
|
+
# Get warnings for specific administrative division
|
|
194
|
+
vilnius_warnings = await api.get_weather_warnings("Vilniaus miesto")
|
|
195
|
+
print(f"Warnings for Vilnius: {len(vilnius_warnings)}")
|
|
196
|
+
|
|
197
|
+
for warning in vilnius_warnings:
|
|
198
|
+
print(f"- {warning.warning_type} ({warning.severity})")
|
|
199
|
+
|
|
200
|
+
asyncio.run(fetch_warnings())
|
|
201
|
+
asyncio.run(fetch_warnings_for_area())
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Data Models
|
|
205
|
+
|
|
206
|
+
The package includes several data models to represent the API responses:
|
|
207
|
+
|
|
208
|
+
### Coordinates
|
|
209
|
+
|
|
210
|
+
Represents geographic coordinates.
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from meteo_lt import Coordinates
|
|
214
|
+
|
|
215
|
+
coords = Coordinates(latitude=54.6872, longitude=25.2797)
|
|
216
|
+
print(coords)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Place
|
|
220
|
+
|
|
221
|
+
Represents a place with associated metadata.
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from meteo_lt import Place
|
|
225
|
+
|
|
226
|
+
place = Place(code="vilnius", name="Vilnius", administrative_division="Vilnius City Municipality", country="LT", coordinates=coords)
|
|
227
|
+
print(place.latitude, place.longitude)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### ForecastTimestamp
|
|
231
|
+
|
|
232
|
+
Represents a timestamp within the weather forecast, including various weather parameters.
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from meteo_lt import ForecastTimestamp
|
|
236
|
+
|
|
237
|
+
forecast_timestamp = ForecastTimestamp(
|
|
238
|
+
datetime="2024-07-23T12:00:00+00:00",
|
|
239
|
+
temperature=25.5,
|
|
240
|
+
apparent_temperature=27.0,
|
|
241
|
+
condition_code="clear",
|
|
242
|
+
wind_speed=5.0,
|
|
243
|
+
wind_gust_speed=8.0,
|
|
244
|
+
wind_bearing=180,
|
|
245
|
+
cloud_coverage=20,
|
|
246
|
+
pressure=1012,
|
|
247
|
+
humidity=60,
|
|
248
|
+
precipitation=0
|
|
249
|
+
)
|
|
250
|
+
print(forecast_timestamp.condition)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Forecast
|
|
254
|
+
|
|
255
|
+
Represents the weather forecast for a place, containing multiple forecast timestamps.
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from meteo_lt import Forecast
|
|
259
|
+
|
|
260
|
+
forecast = Forecast(
|
|
261
|
+
place=place,
|
|
262
|
+
forecast_created=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
263
|
+
forecast_timestamps=[forecast_timestamp]
|
|
264
|
+
)
|
|
265
|
+
print(forecast.current_conditions().temperature)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### WeatherWarning
|
|
269
|
+
|
|
270
|
+
Represents a weather warning for a specific area.
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from meteo_lt import WeatherWarning
|
|
274
|
+
|
|
275
|
+
warning = WeatherWarning(
|
|
276
|
+
county="Vilniaus apskritis",
|
|
277
|
+
warning_type="frost",
|
|
278
|
+
severity="Moderate",
|
|
279
|
+
description="Ground surface frost 0-5 degrees in many places",
|
|
280
|
+
start_time="2024-07-23T12:00:00Z",
|
|
281
|
+
end_time="2024-07-23T18:00:00Z"
|
|
282
|
+
)
|
|
283
|
+
print(f"Warning for {warning.county}: {warning.description}")
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Contributing
|
|
287
|
+
|
|
288
|
+
Contributions are welcome! For major changes please open an issue to discuss or submit a pull request with your changes. If you want to contribute you can use devcontainers in vscode for easiest setup follow [instructions here](.devcontainer/README.md).
|
|
289
|
+
|
|
290
|
+
***
|
|
291
|
+
|
|
292
|
+
[commits-shield]: https://img.shields.io/github/commit-activity/y/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
293
|
+
[commits]: https://github.com/Brunas/meteo_lt-pkg/commits/main
|
|
294
|
+
[license-shield]: https://img.shields.io/github/license/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
295
|
+
[maintenance-shield]: https://img.shields.io/badge/maintainer-Brunas%20%40Brunas-blue.svg?style=flat-square
|
|
296
|
+
[releases-shield]: https://img.shields.io/github/release/Brunas/meteo_lt-pkg.svg?style=flat-square
|
|
297
|
+
[releases]: https://github.com/Brunas/meteo_lt-pkg/releases
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""init.py"""
|
|
2
|
+
|
|
3
|
+
from .api import MeteoLtAPI
|
|
4
|
+
from .models import Coordinates, Place, ForecastTimestamp, Forecast, WeatherWarning
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"MeteoLtAPI",
|
|
8
|
+
"Coordinates",
|
|
9
|
+
"Place",
|
|
10
|
+
"ForecastTimestamp",
|
|
11
|
+
"Forecast",
|
|
12
|
+
"WeatherWarning",
|
|
13
|
+
]
|