NOAA.Observations.Station (NOAA Observations v0.4.37) View Source

Fetches the latest observation for a given NOAA station.

Link to this section Summary

Functions

Fetches the latest observation for a given NOAA station.

Link to this section Types

Specs

dict() :: %{required(t()) => name()}

Specs

name() :: String.t()

Specs

obs() :: map()

Specs

t() :: String.t()

Link to this section Functions

Specs

obs({t(), name()}, Keyword.t()) :: {:ok, obs()} | {:error, String.t()}

Fetches the latest observation for a given NOAA station.

Returns a tuple of either {:ok, obs} or {:error, text}.

Parameters

  • {station, name} - NOAA station
  • url_templates - URL templates

Examples

iex> alias NOAA.Observations.Station
iex> url_templates = [
...>   station:
...>     "https://w1.weather.gov/xml/current_obs/display.php?stid=" <>
...>       "<%=station%>"
...> ]
iex> {:ok, obs} = Station.obs({"KFSO", "KFSO name"}, url_templates)
iex> is_map(obs) and
...> is_binary(obs["temp_c"]) and is_binary(obs["wind_mph"])
true

iex> alias NOAA.Observations.Station
iex> url_templates = [
...>   station:
...>     "htp://w1.weather.gov/xml/current_obs/display.php?stid=" <>
...>       "<%=station%>"
...> ]
iex> {:error, text} = Station.obs({"KFSO", "KFSO name"}, url_templates)
iex> text
"reason => :nxdomain"

iex> alias NOAA.Observations.Station
iex> url_templates = [
...>   station:
...>     "https://w1.weather.gov/xml/past_obs/display.php?stid=" <>
...>       "<%=station%>"
...> ]
iex> {:error, text} = Station.obs({"KFSO", "KFSO name"}, url_templates)
iex> text
"status code 404 ⇒ Not Found"