use noaa_weather_client::apis::configuration::Configuration;
use noaa_weather_client::apis::{alerts, points, stations};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Configuration::default();
println!("🌦️ NOAA Weather Client - Basic Usage Example\n");
let coordinates = "39.7456,-94.5692";
println!(
"📍 Getting weather information for coordinates: {}",
coordinates
);
println!("\n1️⃣ Getting point metadata...");
match points::get_point(&config, coordinates).await {
Ok(point_data) => {
let properties = &point_data.properties;
println!(" ✅ Forecast Office: {:?}", properties.forecast_office);
println!(
" ✅ Grid Coordinates: {},{}",
properties.grid_x.unwrap_or(0),
properties.grid_y.unwrap_or(0)
);
if let Some(time_zone) = &properties.time_zone {
println!(" ✅ Time Zone: {}", time_zone);
}
}
Err(error) => {
eprintln!(" ❌ Error getting point data: {}", error);
}
}
println!("\n2️⃣ Getting active weather alerts...");
let alert_params = alerts::ActiveAlertsParams::default();
match alerts::get_active_alerts(&config, alert_params).await {
Ok(alerts_data) => {
println!(" ✅ Found {} active alerts", alerts_data.features.len());
for (index, alert_feature) in alerts_data.features.iter().take(3).enumerate() {
if let Some(properties) = &alert_feature.properties {
println!(
" {}. {}",
index + 1,
properties.event.as_deref().unwrap_or("Unknown Event")
);
if let Some(areas) = &properties.area_desc {
println!(" Areas: {}", areas);
}
}
}
}
Err(error) => {
eprintln!(" ❌ Error getting alerts: {}", error);
}
}
println!("\n3️⃣ Getting nearby weather stations...");
match points::get_point_stations(&config, coordinates).await {
Ok(stations_data) => {
println!(
" ✅ Found {} nearby stations",
stations_data.features.len()
);
if let Some(first_station) = stations_data.features.first()
&& let Some(station_id) = &first_station.properties.station_identifier
{
println!(
" 📡 Getting latest observation from station: {}",
station_id
);
match stations::get_latest_observations(&config, station_id, None).await {
Ok(observation) => {
let props = &observation.properties;
println!(
" ✅ Station: {}",
props.station_name.as_deref().unwrap_or("Unknown")
);
if let Some(temp) = &props.temperature
&& let Some(temp_value) = temp.value
{
println!(" 🌡️ Temperature: {:.1}°C", temp_value);
}
if let Some(desc) = &props.text_description {
println!(" ☁️ Conditions: {}", desc);
}
if let Some(timestamp) = &props.timestamp {
println!(" ⏰ Observed: {}", timestamp);
}
}
Err(error) => {
eprintln!(" ❌ Error getting observation: {}", error);
}
}
}
}
Err(error) => {
eprintln!(" ❌ Error getting stations: {}", error);
}
}
println!("\n✨ Example completed!");
println!("\n💡 Try running other examples:");
println!(" just example-alerts");
println!(" just examples # Run all examples");
Ok(())
}