use chrono::NaiveDate;
use sobry_api::{Client, DailyPricesRequest, Granularity, TaxMode};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("SOBRY_API_KEY")
.map_err(|_| "set the SOBRY_API_KEY environment variable before running this example")?;
let client = Client::new(api_key)?;
let mut request = DailyPricesRequest::new()
.days(4)
.granularity(Granularity::Hour)
.tax_mode(TaxMode::IncludingTax);
if let Ok(day) = std::env::var("SOBRY_DAY") {
request = request.day(NaiveDate::parse_from_str(&day, "%Y-%m-%d")?);
}
let prices = client.daily_prices(&request).await?;
for point in prices {
println!(
"{} {} {:>8.5} EUR/kWh {:<6?}{}",
point.date,
point.time.format("%H:%M"),
point.price,
point.color_label,
if point.estimated { " (forecast)" } else { "" },
);
}
Ok(())
}