diff options
author | Matt Kohls <mattkohls13@gmail.com> | 2023-10-22 18:39:15 -0400 |
---|---|---|
committer | Matt Kohls <mattkohls13@gmail.com> | 2023-10-22 18:39:15 -0400 |
commit | 7690f350671cd22868d04f91d5423b56c14ad107 (patch) | |
tree | d29f05722f083a93083feec1a0fc7e45274d1e07 /src/weather_gov_json.rs | |
download | weather-data-aggregator-7690f350671cd22868d04f91d5423b56c14ad107.tar.gz weather-data-aggregator-7690f350671cd22868d04f91d5423b56c14ad107.tar.bz2 weather-data-aggregator-7690f350671cd22868d04f91d5423b56c14ad107.zip |
Initial bits to get weather.gov info
Hits up weather.gov and publishes info to a local mqtt broker, bits work
in progress
Diffstat (limited to 'src/weather_gov_json.rs')
-rw-r--r-- | src/weather_gov_json.rs | 169 |
1 files changed, 169 insertions, 0 deletions
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<Vec<Vec<f32>>>, +} + +#[derive(Deserialize, Debug)] +pub struct GeoCode { + pub SAME: Vec<String>, + pub UGC: Vec<String>, +} + + +/** + * 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<Period>, +} + +#[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<String>, + 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<Features>, + pub title: String, + pub updated: String, +} + +#[derive(Deserialize, Debug)] +pub struct Features { + pub id: String, + pub r#type: String, + pub geometry: Option<Geometry>, + 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<String>, + pub references: Vec<AlertReferences>, + pub sent: String, + pub effective: String, + pub onset: Option<String>, + pub expires: String, + pub ends: Option<String>, + 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<String>, + pub description: String, + pub instruction: Option<String>, + pub response: String, + #[serde(skip)] + pub parameters: Vec<String>, +} + +#[derive(Deserialize, Debug)] +pub struct AlertReferences { + #[serde(rename = "@id")] + pub id: String, + pub identifier: String, + pub sender: String, + pub sent: String, +} + +} // End of module |