Skip to content

Commit

Permalink
weather(metno): weathericon API was terminated, use pre-fetched data (#…
Browse files Browse the repository at this point in the history
…1940)

* weather(metno): weathericon API was terminated, use pre-fetched data

* update NEWS.md
  • Loading branch information
MaxVerevkin authored Sep 2, 2023
1 parent c0b43af commit 4397c39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# i3status-rust 0.32.1 [unreleased]

### Bug Fixes and Improvements

* Weather(metno): stop using an API which was terminated on August 31, 2023. The functionality of the block is not affected, but all i3status-rust versions older than 0.32.1 will be unable to use met.no weather service.

# i3status-rust 0.32.0

### Breaking Changes
Expand Down
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ allowCompoundWords: true
ignorePaths:
- target/
- man/
- src/blocks/weather/met_no_legends.json
ignoreRegExpList:
# Ignore usernames that are @'d
- /@[\w-]*/g
Expand Down
21 changes: 6 additions & 15 deletions src/blocks/weather/met_no.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub struct Config {

pub(super) struct Service<'a> {
config: &'a Config,
legend: LegendsStore,
legend: &'static LegendsStore,
}

impl<'a> Service<'a> {
pub(super) async fn new(config: &'a Config) -> Result<Service<'a>> {
Ok(Self {
config,
legend: get_legend.retry(&ExponentialBuilder::default()).await?,
legend: LEGENDS.as_ref().error("Invalid legends file")?,
})
}
}
Expand Down Expand Up @@ -90,19 +90,10 @@ struct ForecastTimeInstant {
relative_humidity: Option<f64>,
}

const LEGENDS_URL: &str = "https://api.met.no/weatherapi/weathericon/2.0/legends";
const FORECAST_URL: &str = "https://api.met.no/weatherapi/locationforecast/2.0/compact";
static LEGENDS: Lazy<Option<LegendsStore>> =
Lazy::new(|| serde_json::from_str(include_str!("met_no_legends.json")).ok());

async fn get_legend() -> Result<LegendsStore> {
REQWEST_CLIENT
.get(LEGENDS_URL)
.send()
.await
.error("Failed to fetch legend from met.no")?
.json()
.await
.error("Legend replied in unknown format")
}
const FORECAST_URL: &str = "https://api.met.no/weatherapi/locationforecast/2.0/compact";

fn translate(legend: &LegendsStore, summary: &str, lang: &ApiLanguage) -> String {
legend
Expand Down Expand Up @@ -161,7 +152,7 @@ impl WeatherProvider for Service<'_> {
.split('_')
.next()
.unwrap();
let translated = translate(&self.legend, summary, lang);
let translated = translate(self.legend, summary, lang);

let temp = instant.air_temperature.unwrap_or_default();
let humidity = instant.relative_humidity.unwrap_or_default();
Expand Down
1 change: 1 addition & 0 deletions src/blocks/weather/met_no_legends.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"clearsky":{"desc_en":"Clear sky","desc_nb":"Klarvær","desc_nn":"Klårvêr","old_id":"1","variants":["day","night","polartwilight"]},"cloudy":{"desc_en":"Cloudy","desc_nb":"Skyet","desc_nn":"Skya","old_id":"4","variants":null},"fair":{"desc_en":"Fair","desc_nb":"Lettskyet","desc_nn":"Lettskya","old_id":"2","variants":["day","night","polartwilight"]},"fog":{"desc_en":"Fog","desc_nb":"Tåke","desc_nn":"Skodde","old_id":"15","variants":null},"heavyrain":{"desc_en":"Heavy rain","desc_nb":"Kraftig regn","desc_nn":"Kraftig regn","old_id":"10","variants":null},"heavyrainandthunder":{"desc_en":"Heavy rain and thunder","desc_nb":"Kraftig regn og torden","desc_nn":"Kraftig regn og torevêr","old_id":"11","variants":null},"heavyrainshowers":{"desc_en":"Heavy rain showers","desc_nb":"Kraftige regnbyger","desc_nn":"Kraftige regnbyer","old_id":"41","variants":["day","night","polartwilight"]},"heavyrainshowersandthunder":{"desc_en":"Heavy rain showers and thunder","desc_nb":"Kraftige regnbyger og torden","desc_nn":"Kraftige regnbyer og torevêr","old_id":"25","variants":["day","night","polartwilight"]},"heavysleet":{"desc_en":"Heavy sleet","desc_nb":"Kraftig sludd","desc_nn":"Kraftig sludd","old_id":"48","variants":null},"heavysleetandthunder":{"desc_en":"Heavy sleet and thunder","desc_nb":"Kraftig sludd og torden","desc_nn":"Kraftig sludd og torevêr","old_id":"32","variants":null},"heavysleetshowers":{"desc_en":"Heavy sleet showers","desc_nb":"Kraftige sluddbyger","desc_nn":"Kraftige sluddbyer","old_id":"43","variants":["day","night","polartwilight"]},"heavysleetshowersandthunder":{"desc_en":"Heavy sleet showers and thunder","desc_nb":"Kraftige sluddbyger og torden","desc_nn":"Kraftige sluddbyer og torevêr","old_id":"27","variants":["day","night","polartwilight"]},"heavysnow":{"desc_en":"Heavy snow","desc_nb":"Kraftig snø","desc_nn":"Kraftig snø","old_id":"50","variants":null},"heavysnowandthunder":{"desc_en":"Heavy snow and thunder","desc_nb":"Kraftig snø og torden","desc_nn":"Kraftig snø og torevêr","old_id":"34","variants":null},"heavysnowshowers":{"desc_en":"Heavy snow showers","desc_nb":"Kraftige snøbyger","desc_nn":"Kraftige snøbyer","old_id":"45","variants":["day","night","polartwilight"]},"heavysnowshowersandthunder":{"desc_en":"Heavy snow showers and thunder","desc_nb":"Kraftige snøbyger og torden","desc_nn":"Kraftige snøbyer og torevêr","old_id":"29","variants":["day","night","polartwilight"]},"lightrain":{"desc_en":"Light rain","desc_nb":"Lett regn","desc_nn":"Lett regn","old_id":"46","variants":null},"lightrainandthunder":{"desc_en":"Light rain and thunder","desc_nb":"Lett regn og torden","desc_nn":"Lett regn og torevêr","old_id":"30","variants":null},"lightrainshowers":{"desc_en":"Light rain showers","desc_nb":"Lette regnbyger","desc_nn":"Lette regnbyer","old_id":"40","variants":["day","night","polartwilight"]},"lightrainshowersandthunder":{"desc_en":"Light rain showers and thunder","desc_nb":"Lette regnbyger og torden","desc_nn":"Lette regnbyer og torevêr","old_id":"24","variants":["day","night","polartwilight"]},"lightsleet":{"desc_en":"Light sleet","desc_nb":"Lett sludd","desc_nn":"Lett sludd","old_id":"47","variants":null},"lightsleetandthunder":{"desc_en":"Light sleet and thunder","desc_nb":"Lett sludd og torden","desc_nn":"Lett sludd og torevêr","old_id":"31","variants":null},"lightsleetshowers":{"desc_en":"Light sleet showers","desc_nb":"Lette sluddbyger","desc_nn":"Lette sluddbyer","old_id":"42","variants":["day","night","polartwilight"]},"lightsnow":{"desc_en":"Light snow","desc_nb":"Lett snø","desc_nn":"Lett snø","old_id":"49","variants":null},"lightsnowandthunder":{"desc_en":"Light snow and thunder","desc_nb":"Lett snø og torden","desc_nn":"Lett snø og torevêr","old_id":"33","variants":null},"lightsnowshowers":{"desc_en":"Light snow showers","desc_nb":"Lette snøbyger","desc_nn":"Lette snøbyer","old_id":"44","variants":["day","night","polartwilight"]},"lightssleetshowersandthunder":{"desc_en":"Light sleet showers and thunder","desc_nb":"Lette sluddbyger og torden","desc_nn":"Lette sluddbyer og torevêr","old_id":"26","variants":["day","night","polartwilight"]},"lightssnowshowersandthunder":{"desc_en":"Light snow showers and thunder","desc_nb":"Lette snøbyger og torden","desc_nn":"Lette snøbyer og torevêr","old_id":"28","variants":["day","night","polartwilight"]},"partlycloudy":{"desc_en":"Partly cloudy","desc_nb":"Delvis skyet","desc_nn":"Delvis skya","old_id":"3","variants":["day","night","polartwilight"]},"rain":{"desc_en":"Rain","desc_nb":"Regn","desc_nn":"Regn","old_id":"9","variants":null},"rainandthunder":{"desc_en":"Rain and thunder","desc_nb":"Regn og torden","desc_nn":"Regn og torevêr","old_id":"22","variants":null},"rainshowers":{"desc_en":"Rain showers","desc_nb":"Regnbyger","desc_nn":"Regnbyer","old_id":"5","variants":["day","night","polartwilight"]},"rainshowersandthunder":{"desc_en":"Rain showers and thunder","desc_nb":"Regnbyger og torden","desc_nn":"Regnbyer og torevêr","old_id":"6","variants":["day","night","polartwilight"]},"sleet":{"desc_en":"Sleet","desc_nb":"Sludd","desc_nn":"Sludd","old_id":"12","variants":null},"sleetandthunder":{"desc_en":"Sleet and thunder","desc_nb":"Sludd og torden","desc_nn":"Sludd og torevêr","old_id":"23","variants":null},"sleetshowers":{"desc_en":"Sleet showers","desc_nb":"Sluddbyger","desc_nn":"Sluddbyer","old_id":"7","variants":["day","night","polartwilight"]},"sleetshowersandthunder":{"desc_en":"Sleet showers and thunder","desc_nb":"Sluddbyger og torden","desc_nn":"Sluddbyer og torevêr","old_id":"20","variants":["day","night","polartwilight"]},"snow":{"desc_en":"Snow","desc_nb":"Snø","desc_nn":"Snø","old_id":"13","variants":null},"snowandthunder":{"desc_en":"Snow and thunder","desc_nb":"Snø og torden","desc_nn":"Snø og torevêr","old_id":"14","variants":null},"snowshowers":{"desc_en":"Snow showers","desc_nb":"Snøbyger","desc_nn":"Snøbyer","old_id":"8","variants":["day","night","polartwilight"]},"snowshowersandthunder":{"desc_en":"Snow showers and thunder","desc_nb":"Snøbyger og torden","desc_nn":"Snøbyer og torevêr","old_id":"21","variants":["day","night","polartwilight"]}}

0 comments on commit 4397c39

Please sign in to comment.