Skip to main content

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.

GitHub release License issues - Yr-norwegian-water-temperatures-integration Tests

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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Changelog

See Releases for a detailed changelog.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yrwatertemperatures-0.9.8b0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yrwatertemperatures-0.9.8b0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file yrwatertemperatures-0.9.8b0.tar.gz.

File metadata

  • Download URL: yrwatertemperatures-0.9.8b0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for yrwatertemperatures-0.9.8b0.tar.gz
Algorithm Hash digest
SHA256 eb5d94dba045bff00c0bb7cf0f76eb985430a0b5d244ca70156a65ff83c7e372
MD5 fd0323ed2c73f8727eb993f18c78e240
BLAKE2b-256 d95ea37742abe4e2c062f1f58f4a05168b1e270b3934e397f826c218fa2bbb22

See more details on using hashes here.

File details

Details for the file yrwatertemperatures-0.9.8b0-py3-none-any.whl.

File metadata

File hashes

Hashes for yrwatertemperatures-0.9.8b0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cbdda34a996fd630693ba7970e70834696d72d81e0c9123458098f7569f468f
MD5 fa898109503aeb8765a52e6ed400523a
BLAKE2b-256 48f81c35748f56e64436d465179d7303548b1caa85e9bb505eea56c9b9994793

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page