#price #api-client #blocking #date #api-wrapper #api-bindings #hvakosterstrommen

strompris

A simple wrapper of the Strømpris-API from https://hvakosterstrommen.no

3 unstable releases

0.4.1 Jul 20, 2024
0.4.0 Jul 20, 2024
0.3.1 Jul 19, 2024

#808 in Web programming

Download history 258/week @ 2024-07-15 45/week @ 2024-07-22 38/week @ 2024-07-29 17/week @ 2024-09-16 9/week @ 2024-09-23 56/week @ 2024-09-30 4/week @ 2024-10-07

86 downloads per month

MIT license

20KB
345 lines

Strømpris

This crate is a wrapper around the Strømpris-API hosted on https://hvakostersttrommen.no.

The crate offers both async and blocking versions of the client, as well as a strongly typed model of the response objects.

Documentation

https://docs.rs/strompris

Usage

Run cargo add strompris to add this crate to your Cargo.toml file.

Example

use strompris::blocking::Strompris;
use strompris::{PriceRegion, Date};

fn main() {
    let date = Date::from_ymd_opt(2024, 1, 31).unwrap();
    let client = Strompris::default();
    let prices = client.get_prices(date, PriceRegion::NO1).unwrap();
    for price in prices.iter() {
        println!("From: {}", price.time_start.time());
        println!("To: {}", price.time_end.time());
        println!("Price: {:.2} NOK\n", price.nok_per_kwh);
    }
}

lib.rs:

This crate offers a wrapper of the Strømpris API offered by HvaKosterStrømmen.

The crate is designed to be as simple as the API itself, so only one method is exposed: A method for getting the prices for a given region on a given day.

This crate offers both async and blocking ways of fetching prices. See the blocking module for more information on the blocking API.

See www.hvakosterstrommen.no for more info about the API.

Example using tokio:

use strompris::{Strompris, PriceRegion, Date, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let date = Date::from_ymd_opt(2024, 1, 31).unwrap();
    let client = Strompris::default();
    let prices = client.get_prices(date, PriceRegion::NO1).await?;
    for price in prices.iter() {
        println!("Price: {:.2}", price.nok_per_kwh);
        println!("From: {}", price.time_start.time());
        println!("To: {}", price.time_end.time());
    }
    Ok(())
}

Dependencies

~5–16MB
~223K SLoC