nwslib/
forecast_json.rs

1// nws-cli, a CLI application that gets the forecast or current conditions from the National Weather Service
2//     Copyright (C) 2024 Margaret Joan Miller
3
4//     This program is free software: you can redistribute it and/or modify
5//     it under the terms of the GNU General Public License as published by
6//     the Free Software Foundation, either version 3 of the License, or
7//     (at your option) any later version.
8
9//     This program is distributed in the hope that it will be useful,
10//     but WITHOUT ANY WARRANTY; without even the implied warranty of
11//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12//     GNU General Public License for more details.
13
14//     You should have received a copy of the GNU General Public License
15//     along with this program.  If not, see <https://www.gnu.org/licenses/>
16
17
18pub mod forecast_json {
19    use serde::{Serialize, Deserialize};
20
21
22    #[derive(Debug, Clone, Serialize, Deserialize)]
23    pub struct ForecastJson {
24        #[serde(rename = "@context")]
25        pub context: Vec<ContextElement>,
26        pub geometry: Geometry,
27        pub properties: Properties,
28        #[serde(rename = "type")]
29        pub forecast_type: String,
30    }
31
32    #[derive(Debug, Clone, Serialize, Deserialize)]
33    #[serde(untagged)]
34    pub enum ContextElement {
35        ContextClass(ContextClass),
36        String(String),
37    }
38
39    #[derive(Debug, Clone, Serialize, Deserialize)]
40    pub struct ContextClass {
41        #[serde(rename = "@version")]
42        pub version: String,
43        #[serde(rename = "@vocab")]
44        pub vocab: String,
45        pub geo: String,
46        pub unit: String,
47        pub wx: String,
48    }
49
50    #[derive(Debug, Clone, Serialize, Deserialize)]
51    pub struct Geometry {
52        pub coordinates: Vec<Vec<Vec<f64>>>,
53        #[serde(rename = "type")]
54        pub geometry_type: String,
55    }
56
57    #[derive(Debug, Clone, Serialize, Deserialize)]
58    #[serde(rename_all = "camelCase")]
59    pub struct Properties {
60        pub elevation: Elevation,
61        pub forecast_generator: String,
62        pub generated_at: String,
63        pub periods: Vec<Period>,
64        pub units: String,
65        pub update_time: String,
66        pub valid_times: String,
67    }
68
69    #[derive(Debug, Clone, Serialize, Deserialize)]
70    #[serde(rename_all = "camelCase")]
71    pub struct Elevation {
72        pub unit_code: String,
73        pub value: f64,
74    }
75
76    #[derive(Debug, Clone, Serialize, Deserialize)]
77    #[serde(rename_all = "camelCase")]
78    pub struct Period {
79        pub detailed_forecast: String,
80        pub end_time: String,
81        pub icon: String,
82        pub is_daytime: bool,
83        pub name: String,
84        pub number: i64,
85        pub probability_of_precipitation: ProbabilityOfPrecipitation,
86        pub short_forecast: String,
87        pub start_time: String,
88        pub temperature: i64,
89        pub temperature_trend: String,
90        pub temperature_unit: String,
91        pub wind_direction: String,
92        pub wind_speed: String,
93    }
94
95    #[derive(Debug, Clone, Serialize, Deserialize)]
96    #[serde(rename_all = "camelCase")]
97    pub struct ProbabilityOfPrecipitation {
98        pub unit_code: String,
99    }
100
101}