Skip to content

Commit

Permalink
block[weather]: Add support for the US National Weather Service (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cognoscan authored Jul 10, 2024
1 parent d882fb6 commit 3374847
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 2 deletions.
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ words:
- execvp
- favg
- fcntl
- flurr
- fmax
- fmin
- getaddr
Expand Down
21 changes: 19 additions & 2 deletions src/blocks/weather.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Current weather
//!
//! This block displays local weather and temperature information. In order to use this block, you
//! will need access to a supported weather API service. At the time of writing, OpenWeatherMap and
//! met.no are supported.
//! will need access to a supported weather API service. At the time of writing, OpenWeatherMap,
//! met.no, and the US National Weather Service are supported.
//!
//! Configuring this block requires configuring a weather service, which may require API keys and
//! other parameters.
Expand Down Expand Up @@ -56,6 +56,18 @@
//!
//! Met.no does not support location name, but if autolocate is enabled then autolocate's city value is used.
//!
//! # US National Weather Service Options
//!
//! Key | Values | Required | Default
//! ----|--------|----------|--------
//! `name` | `nws`. | Yes | None
//! `coordinates` | GPS latitude longitude coordinates as a tuple, example: `["39.2362","9.3317"]` | Required if `autolocate = false` | None
//! `forecast_hours` | How many hours should be forecast | No | 12
//! `units` | Either `"metric"` or `"imperial"`. | No | `"metric"`
//!
//! Forecasts gather statistics from each hour between now and the `forecast_hours` value, and
//! provide predicted weather at the set number of hours into the future.
//!
//! # Available Format Keys
//!
//! Key | Value | Type | Unit
Expand Down Expand Up @@ -125,6 +137,7 @@ use crate::formatting::Format;
use super::prelude::*;

pub mod met_no;
pub mod nws;
pub mod open_weather_map;

const IP_API_URL: &str = "https://ipapi.co/json";
Expand Down Expand Up @@ -163,6 +176,7 @@ trait WeatherProvider {
pub enum WeatherService {
OpenWeatherMap(open_weather_map::Config),
MetNo(met_no::Config),
Nws(nws::Config),
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -308,6 +322,9 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
WeatherService::OpenWeatherMap(service_config) => {
Box::new(open_weather_map::Service::new(config.autolocate, service_config).await?)
}
WeatherService::Nws(service_config) => {
Box::new(nws::Service::new(config.autolocate, service_config).await?)
}
};

let autolocate_interval = config.autolocate_interval.unwrap_or(config.interval);
Expand Down
Loading

0 comments on commit 3374847

Please sign in to comment.