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

Fetches the stations for a US state/territory.

Link to this section Summary

Functions

Fetches the stations for a US state/territory.

Link to this section Types

Link to this section Functions

Link to this function

stations(state, url_templates)

View Source

Specs

stations(t(), Keyword.t()) ::
  {:ok, NOAA.Observations.Station.dict()} | {:error, String.t()}

Fetches the stations for a US state/territory.

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

Parameters

  • state - US state/territory code
  • url_templates - URL templates

Examples

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:ok, %{"KFSO" => name}} = State.stations("vt", url_templates)
iex> name
"Franklin County State Airport"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "http://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 301 ⇒ Moved Permanently"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://www.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 302 ⇒ Found"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "https://w1.weather.gov/xml/past_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"status code 404 ⇒ Not Found"

iex> alias NOAA.Observations.State
iex> url_templates = [
...>   state:
...>     "htp://w1.weather.gov/xml/current_obs/seek.php?state=" <>
...>       "<%=state%>&Find=Find"
...> ]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"reason => :nxdomain"

iex> alias NOAA.Observations.State
iex> url_templates = [state: "http://localhost:1"]
iex> {:error, text} = State.stations("vt", url_templates)
iex> text
"reason => :econnrefused"