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

Fetches the latest observation for a given NOAA station.

Summary

Types

Erroneous station

Station ID

Station name

NOAA weather observation

t()

NOAA station

Functions

Fetches the latest observation for a given NOAA station.

Types

error()

@type error() :: map()

Erroneous station

id()

@type id() :: <<_::32>>

Station ID

name()

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

Station name

observation()

@type observation() :: map()

NOAA weather observation

t()

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

NOAA station

Functions

observation(station, state_code)

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

Fetches the latest observation for a given NOAA station.

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

Parameters

  • {station_id, station_name} - NOAA station
  • state_code - US state/territory code

Examples

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> :ok = TemplatesAgent.refresh()
iex> {:ok, observation} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> is_map(observation) and is_binary(observation["wind_mph"])
true

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...>   "htp://forecast.weather.gov/xml/current_obs" <>
...>     "/display.php?stid=<%=station_id%>"
iex> TemplatesAgent.update_station_template(template)
iex> {:error, %{error_text: text, error_code: code, station_id: id}} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {text, code, id}
{"Non-Existent Domain", :nxdomain, "KFSO"}

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...>   "https://forecast.weather.gov/xml/past_obs" <>
...>     "/display.php?stid=<%=station_id%>"
iex> TemplatesAgent.update_station_template(template)
iex> {:error, %{error_text: text, error_code: code, station_id: id}} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {text, code, id}
{"Not Found", 404, "KFSO"}