View Source NOAA.Observations (NOAA Observations v0.4.58)

Fetches weather observations for a US state/territory code.

Summary

Functions

Fetches weather observations for a state_code.

Functions

fetch(state_code, options \\ [])

@spec fetch(NOAA.Observations.State.code(), Keyword.t()) ::
  %{
    optional(:ok) => [NOAA.Observations.Station.observation()],
    optional(:error) => [NOAA.Observations.Station.error()]
  }
  | {:error, NOAA.Observations.State.error()}

Fetches weather observations for a state_code.

Parameters

  • state_code - US state/territory code

Examples

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> :ok = TemplatesAgent.refresh()
iex> %{ok: observations} = Observations.fetch("VT")
iex> Enum.all?(observations, &is_map/1) and length(observations) > 0
true

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> template =
...>   "http://forecast.weather.gov/xml/current_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> {:error,
...>  %{
...>    error_code: 301,
...>    error_text: "Moved Permanently",
...>    state_url: url
...>  }} = Observations.fetch("VT", template)
iex> url
"http://forecast.weather.gov/xml/current_obs/seek.php?state=VT&Find=Find"

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> template =
...>   "https://www.weather.gov/xml/current_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> {:error,
...>  %{
...>    error_code: 302,
...>    error_text: "Found (Moved Temporarily)",
...>    state_url: url
...>  }} = Observations.fetch("VT", template)
...> url
"https://www.weather.gov/xml/current_obs/seek.php?state=VT&Find=Find"

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> template =
...>   "https://forecast.weather.gov/xml/past_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> {:error,
...>  %{error_code: 404, error_text: "Not Found", state_url: url}} =
...>   Observations.fetch("VT", template)
iex> url
"https://forecast.weather.gov/xml/past_obs/seek.php?state=VT&Find=Find"

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> template =
...>   "htp://forecast.weather.gov/xml/current_obs" <>
...>     "/seek.php?state=<%=state_code%>&Find=Find"
iex> TemplatesAgent.update_state_template(template)
iex> {:error,
...>  %{
...>    error_code: :nxdomain,
...>    error_text: "Non-Existent Domain",
...>    state_url: url
...>  }} = Observations.fetch("VT", template)
iex> url
"htp://forecast.weather.gov/xml/current_obs/seek.php?state=VT&Find=Find"

iex> alias NOAA.Observations
iex> alias NOAA.Observations.TemplatesAgent
iex> template = "http://localhost:65535"
iex> TemplatesAgent.update_state_template(template)
iex> {:error,
...>  %{
...>    error_code: :econnrefused,
...>    error_text: "Connection Refused By Server",
...>    state_url: url
...>  }} = Observations.fetch("VT", template)
iex> url
"http://localhost:65535"