9 个版本
0.1.8 | 2024 年 6 月 1 日 |
---|---|
0.1.7 | 2024 年 5 月 31 日 |
0.1.5 | 2024 年 2 月 23 日 |
0.1.3 | 2023 年 10 月 17 日 |
0.1.1 | 2023 年 4 月 28 日 |
#213 in 网页编程
3,684 每月下载量
82KB
2K SLoC
OpenWeather_SDK
这个库是一个用于向 OpenWeather API 发送请求的 Rust 小型包装器。这个库包括
支持的查询类型
入门指南
初始化库
use openweather_sdk::{OpenWeather, Units, Language};
let openweather = OpenWeather::new(
"MY_PRIVATE_API_KEY".to_string(),
Units::Imperial,
Language::English
);
let lat = 38.795021;
let lon = -77.273300;
let count = 10;
let forecast_response = openweather.forecast.call(lat, lon, count).await;
OneCall 查询
let lat = 38.795021;
let lon = -77.273300;
let historical_date = 1606223802;
let date = "2024-05-31" // YYYY-MM-DD format
// get one call data for current weather
let res = openweather.one_call.call(lat, lon).await;
// get one call data for historical weather
let res2 = openweather.one_call.historical(lat, lon, historical_date).await;
// get one call data for daily aggregation
let res3 = openweather.one_call.call_daily_aggregation(lat, lon, date, None).await;
// get one call data for weather overview
let res4 = openweather.one_call.weather_overview(lat, lon, date).await;
// customize response fields
openweather.one_call.fields.minutely = false;
openweather.one_call.fields.hourly = false;
let res5 = openweather.one_call.call(lat, lon).await;
预报查询
let lat = 38.795021;
let lon = -77.273300;
let count = 10;
// get forecast data with specified number of timestamps
let res = openweather.forecast.call(lat, lon, count).await;
当前查询
let lat = 38.795021;
let lon = -77.273300;
// get current forecast data
let res = openweather.current.call(lat, lon).await;
地图查询
let lat = 38.795021;
let lon = -77.273300;
let zoom = 1;
let x_tiles = 1;
let y_tiles = 1;
// get various types of map data
let cloud_map = openweather.maps.get_cloud_map(zoom, x_tiles, y_tiles).await;
let precip_map = openweather.maps.get_precipitation_map(zoom, x_tiles, y_tiles).await;
let temp_map = openweather.maps.get_temperature_map(zoom, x_tiles, y_tiles).await;
let wind_spd_map = openweather.maps.get_wind_speed_map(zoom, x_tiles, y_tiles).await;
let pressure_map = openweather.maps.get_pressure_map(zoom, x_tiles, y_tiles).await;
空气污染查询
let lat = 38.795021;
let lon = -77.273300;
// get current and forecast air pollution data
let res = openweather.air_pollution.get_current_air_pollution(lat, lon).await;
let res2 = openweather.air_pollution.get_forecast_air_pollution(lat, lon).await;
// get historical air pollution data with start and end timestamps
let start = 1606223802;
let end = 1606482999;
let res3 = openweather.air_pollution.get_historical_air_pollution(lat, lon, start, end).await;
地理编码查询
let lat = 38.795021;
let lon = -77.273300;
let city = "Washington";
let state = "DC";
let country = "US";
let limit = 5;
let res = openweather.geocoding.get_geocoding(city, Some(state), Some(country), limit).await;
let res2 = openweather.geocoding.get_geocoding_by_zip_code("20001", None).await;
let res3 = openweather.geocoding.get_location_data(lat, lon, limit).await;
依赖项
- reqwest ^0.11
- tokio ^1.0
- serde ^1.0.152
许可证
- MIT
贡献
- 欢迎提交拉取请求。对于重大更改,请首先打开一个问题来讨论您想更改的内容。
- 请确保根据需要更新测试和文档。
作者
依赖项
~6–19MB
~270K SLoC