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

Fetches the latest observation for a given NOAA station.

Summary

Types

Station ID

Station name

NOAA weather observation

t()

NOAA station

Functions

Fetches the latest observation for a given NOAA station.

Types

@type id() :: String.t()

Station ID

@type name() :: String.t()

Station name

@type observation() :: map()

NOAA weather observation

@type t() :: {id(), name()}

NOAA station

Functions

Link to this function

observation(station, code, url_templates)

View Source
@spec observation(t(), NOAA.Observations.State.code(), Keyword.t()) ::
  {:ok, observation()} | {:error, String.t()}

Fetches the latest observation for a given NOAA station.

Returns either tuple {:ok, observation} or tuple {:error, text}.

Parameters

  • {id, 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, observation} =
...>   Station.observation({"KFSO", "KFSO name"}, "vt", url_templates)
iex> is_map(observation) and
...> is_binary(observation["temp_c"]) and
...> is_binary(observation["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.observation({"KFSO", "KFSO name"}, "vt", 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.observation({"KFSO", "KFSO name"}, "vt", url_templates)
iex> text
"status code 404 ⇒ Not Found"