use cinnamon::client::NightscoutClient;
use std::env;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let url = env::var("NS_URL").expect("NS_URL not set");
let token = env::var("NS_TOKEN").expect("NS_TOKEN not set");
let client = NightscoutClient::new(&url)?.with_secret(token);
println!("Fetching latest glucose data.");
let entries = client.sgv().get().limit(5).send().await?;
for entry in entries {
let time = entry
.datetime()
.map(|dt| dt.to_rfc3339())
.unwrap_or_else(|| "unknown".to_string());
println!("[{}] {} mg/dl ({:?})", time, entry.sgv, entry.direction);
}
Ok(())
}