A Python client to fetch water temperatures in Norway from YR.no.
Project description
Norway Water Temperature API Client
A Python package to fetch water temperature data from various locations in Norway.
Installation
pip install yrwatertemperatures
API key
To use this package, you need an API key from yr.no, see https://hjelp.yr.no/hc/no/articles/5949243432850-API-for-badetemperaturer for more info.
Usage
First, you'll need to get an API key from the provider of the water temperature data.
Then, you can use the package like this:
"""Example script to fetch and display water temperatures using the yrwatertemperatures package."""
import asyncio
from aiohttp import ClientSession, ClientError
from yrwatertemperatures import WaterTemperatures
API_KEY = "your_api_key_here" # Replace with your actual API key
async def main() -> None:
"""Main function to fetch and display water temperatures."""
async with ClientSession() as session:
try:
client = WaterTemperatures(API_KEY, session)
temperatures = await client.async_get_all_water_temperatures()
# Print the location and temperature
for temp in temperatures:
print(f"Location: {temp.name}, Temperature: {temp.temperature}°C")
except (ClientError, Exception) as e:
print(f"An error occurred: {e}")
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()
Data Structure
The get_temperatures method returns a list of LocationData objects. Each object has the following attributes:
name (str): The name of the location.
location_id (str): A unique identifier for the location.
latitude (float): The latitude of the location.
longitude (float): The longitude of the location.
elevation (int): The elevation of the location in meters.
county (str): The county where the location is.
municipality (str): The municipality where the location is.
temperature (float): The water temperature in Celsius.
time (datetime): The timestamp of the reading.
source (str): The source of the data (not always present).
Development
For development and contributing to this package:
# Clone the repository
git clone https://github.com/jornpe/yr-norwegian-water-temperatures.git
cd yr-norwegian-water-temperatures
# Install in development mode
pip install -e .[dev]
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
# Run tests with coverage
pytest --cov=yrwatertemperatures --cov-report=html
# Format code
black .
isort .
# Type checking
mypy yrwatertemperatures
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Changelog
See Releases for a detailed changelog.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yrwatertemperatures-1.0.1.tar.gz.
File metadata
- Download URL: yrwatertemperatures-1.0.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82ff982906a3cbc0ccbc412a55833b622fbf46d61458e7c6413f485db18f38fc
|
|
| MD5 |
db7073fa7daa791fb77f38fa062940e4
|
|
| BLAKE2b-256 |
00a63b2869c739dea3f087af1e9ce4f4deea8a5dd7433a44abc2ebd77cf20c96
|
File details
Details for the file yrwatertemperatures-1.0.1-py3-none-any.whl.
File metadata
- Download URL: yrwatertemperatures-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb698ed748f67532df2c9b6146cde06950002a630493c367361c506c0e0b7dd7
|
|
| MD5 |
b796183f5686f95b51a99b0f790759bd
|
|
| BLAKE2b-256 |
450db7912c5024907487ab18fa3d0e0ef959f05183d39f3b47aebeda9398fb05
|