From 7690f350671cd22868d04f91d5423b56c14ad107 Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Sun, 22 Oct 2023 18:39:15 -0400 Subject: Initial bits to get weather.gov info Hits up weather.gov and publishes info to a local mqtt broker, bits work in progress --- src/weather_gov_json.rs | 169 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 src/weather_gov_json.rs (limited to 'src/weather_gov_json.rs') diff --git a/src/weather_gov_json.rs b/src/weather_gov_json.rs new file mode 100644 index 0000000..c25f11e --- /dev/null +++ b/src/weather_gov_json.rs @@ -0,0 +1,169 @@ + +/*! + * Weather.gov JSON Definitions + * + * Various structs to deserialize api responses + * + * Matt Kohls + * GPL v3 + * 2023 + */ + +pub mod weather_gov_json { + +#![allow(non_snake_case)] + +use serde::Deserialize; + +/** + * Common Objects + **/ + +#[derive(Deserialize, Debug)] +pub struct Context { + #[serde(rename = "")] + pub link: String, + pub jsonld: JsonLD, +} + +#[derive(Deserialize, Debug)] +pub struct JsonLD { + #[serde(rename = "@version")] + pub version: String, + pub wx: String, + #[serde(default)] + pub geo: String, + #[serde(default)] + pub unit: String, + #[serde(alias = "@vocab")] + pub vocab: String, +} + +#[derive(Deserialize, Debug)] +pub struct Geometry { + pub r#type: String, + pub coordinates: Vec>>, +} + +#[derive(Deserialize, Debug)] +pub struct GeoCode { + pub SAME: Vec, + pub UGC: Vec, +} + + +/** + * Forecast + * https://www.weather.gov/documentation/services-web-api#/default/gridpoint_forecast + **/ + +#[derive(Deserialize, Debug)] +pub struct Forecast { + #[serde(rename = "@context")] + pub context: Context, + pub r#type: String, + pub geometry: Geometry, + pub properties: ForecastProperties, +} + +#[derive(Deserialize, Debug)] +pub struct ForecastProperties { + pub updated: String, + pub units: String, + pub forecastGenerator: String, + pub generatedAt: String, + pub updateTime: String, + pub validTimes: String, + pub elevation: Elevation, + pub periods: Vec, +} + +#[derive(Deserialize, Debug)] +pub struct Elevation { + pub unitCode: String, + pub value: f32, +} + +#[derive(Deserialize, Debug)] +pub struct Period { + pub number: u32, + pub name: String, + pub startTime: String, + pub endTime: String, + pub isDaytime: bool, + pub temperature: i32, + pub temperatureUnit: String, + pub temperatureTrend: Option, + pub windSpeed: String, + pub windDirection: String, + pub icon: String, + pub shortForecast: String, + pub detailedForecast: String, +} + +/** + * Alerts + * https://www.weather.gov/documentation/services-web-api#/default/alerts_active + **/ + +#[derive(Deserialize, Debug)] +pub struct Alerts { + #[serde(rename = "@context", skip)] + pub context: String, + pub r#type: String, + pub features: Vec, + pub title: String, + pub updated: String, +} + +#[derive(Deserialize, Debug)] +pub struct Features { + pub id: String, + pub r#type: String, + pub geometry: Option, + pub properties: AlertProperties, +} + +#[derive(Deserialize, Debug)] +pub struct AlertProperties { + #[serde(rename = "@id")] + pub aid: String, + #[serde(rename = "@type")] + pub r#type: String, + pub id: String, + pub areaDesc: String, + pub geocode: GeoCode, + pub affectedZones: Vec, + pub references: Vec, + pub sent: String, + pub effective: String, + pub onset: Option, + pub expires: String, + pub ends: Option, + pub status: String, + pub messageType: String, + pub category: String, + pub severity: String, + pub certainty: String, + pub urgency: String, + pub event: String, + pub sender: String, + pub senderName: String, + pub headline: Option, + pub description: String, + pub instruction: Option, + pub response: String, + #[serde(skip)] + pub parameters: Vec, +} + +#[derive(Deserialize, Debug)] +pub struct AlertReferences { + #[serde(rename = "@id")] + pub id: String, + pub identifier: String, + pub sender: String, + pub sent: String, +} + +} // End of module -- cgit v1.2.3