#weather #data #api-wrapper #open-meteo #forecast #accessing #location

open-meteo-api

a simple open-meteo api wrapper to get weather data

1 unstable release

0.1.3 Oct 6, 2023
0.1.2 Oct 6, 2023
0.1.1 Oct 6, 2023
0.1.0 Oct 6, 2023

#2116 in Web programming

Download history 50/week @ 2024-02-19 9/week @ 2024-02-26 7/week @ 2024-03-11 76/week @ 2024-04-01

83 downloads per month

MIT license

25KB
538 lines

// parsed json with (almost) all data you may need
// for more info see open-meteo.com/en/docs

let data1 = OpenMeteo::new() 
        .location("London").await? // add location
        .forecast_days(10)?  // add forecast data
        .current_weather()?  // add current weather data
        .past_days(10)? // add past days data
        .time_zone(TimeZone::EuropeLondon)? // set time zone for using .daily()
        .hourly()? // add hourly weather data
        .daily()? // add daily weather data
        .query()
        .await?;

// using start date and end date

let data2 = OpenMeteo::new()
        .coordinates(51.0, 0.0)? // you can also use .coordinates(lat, lon) to set location
        .start_date("2023-09-01")?
        .end_date("2023-09-10")?
        .time_zone(TimeZone::EuropeLondon)?
        .hourly()?
        .daily()?
        .query()
        .await?;

// accessing data fields
// current_weather, hourly_units, hourly, daily_units, daily have Option type
// fields of ".hourly" and ".daily" have Vec<Option<T>> type

let temperature = data1.current_weather.unwrap().temperature;
let temperature_2m = data2.hourly.unwrap().temperature_2m;

println!("{}", temperature );
println!("{:?}", temperature_2m);
    
Ok(())

Dependencies

~6–20MB
~292K SLoC