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).

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.7b0.tar.gz (10.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.7b0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yrwatertemperatures-0.9.7b0.tar.gz
  • Upload date:
  • Size: 10.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.7b0.tar.gz
Algorithm Hash digest
SHA256 4a857110834c7bab0d369e6dd9d2f206f44e324c90f96bd7afdcbceb499a0b47
MD5 eed329e3c9c2ce71c608c8fed3158e1f
BLAKE2b-256 fcd6242f4f1a5c3fad6a87e82e9f5d922b26fef67273d4719fc07be6aa0b2c91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for yrwatertemperatures-0.9.7b0-py3-none-any.whl
Algorithm Hash digest
SHA256 065e65da7d7b46c90141b1d17bd2f69ff26157dae56a80c950a45c70b8ad7a9c
MD5 7ffda96278da21acba45169e3c4f23a7
BLAKE2b-256 15daf9c23eba6c8dedceb710e34e0ec85d117525c85df19585ecf21441ccfc7f

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